« Return to Thread: Strange result

Re: Strange result

by Benjamin Smith :: Rate this Message:

Reply to Author | View in Thread

So you're trying to develop an array of objects that you can access via a
loop, no? Here's what I've done that I think is similar, and seems to work
pretty well.

Nicely, by keeping object references in an array, you can globalize the array
even though a global variable is itself a reference. So you end up with a
referenced array of references.

<?

Function hideThemAll()
        {
        global $objs;
        foreach($objs AS $obj)
                $obj->Hide();
        return true;
        }

$objs=array();
$objs[]=&New GtkWidget();
$objs[]=&New GtkWidget();

foreach($objs AS $obj)
        {
        $obj->doSomeMethod();
        }

hideThemAll();

?>

I hope this helps - works for me well in a large codebase.

-Ben

On Wednesday 22 October 2008 04:47:31 am AngeloP wrote:

> I want to make a main array named $objs=array()
>  that contains reference to the gtkentry that I' have in into a form
>
> for example I want to have somethig like this:
>
> $foo=array( object_a;object_b .... , last_obj );
>
> so I'm able with a comand like
>
> foreach($foo as $obj )
>
> to print  $obj->get_text(); or have other operations.
>
> Please see the code here under
>
> >From the main program I istantite the class
>
> and then I append the entry object into array by the command
>
> array_push($objs, $test->get_objs0());
>
> but I must  make for two times an array push
>
> I would into class make a local  array push everi gtkentry obj into array
> and then when I get it  with command get_objs
> return the array with two object and push it
> to the main array
>
> with only one command array_push(....); !!!!!!
>
> I have tried to make an array into the class
> but it return no obj where I have made mistake ???
>
>
> Any has some Idea for solution ?
>
>
> Thanks
> -------------------------------------------------
> <?php
>
> class Rad_Entryb extends GtkHbox
> {
>
>   function __construct()
>         {
>           parent::__construct();
>         }
>
>
>       function spacer($container,$gap)
>       {
>         if($container -> get_name()== 'GtkHbox' )
>         {
>          //echo "horizontal spacer: $gap\n";
>          $spacer = new GtkHbox();
>          $spacer -> set_size_request($gap,0);
>          $container -> pack_start($spacer,$false);
>         }
>         else
>         {
>         //echo "vertical spacer: $gap\n";
>          $spacer = new GtkVbox();
>          $spacer -> set_size_request(0,$gap);
>          $container -> pack_start($spacer,$false);
>         }
>       }
>
>       function expandible_spacer($container)
>       {
>         $container->pack_start(new GtkHbox(),true);
>       }
>
> }
>
>
> class One_Label_Two_Field extends Rad_entryb
> {
>
>     private $objs0;
>     private $objs1;
>
>
>
>   function __construct($vbox,$label_uno,$entry_uno,$entry_due)
>         {
>
>          parent::__construct();
>
>
>
>     $this->spacer($this,3);
>
>     $lab= new GtkLabel();
>     $lab->set_text($label_uno);
>
>
>     $this->pack_start($lab,false);
>
>     $entry0= new GtkEntry();
>     $entry0->set_name($entry_uno);
>
>                $this->objs0= $entry0;
>
>     $this->pack_start($entry0,false);
>
>     $entry1= new GtkEntry();
>     $entry1->set_name($entry_due);
>
>                    $this->objs1= $entry1;
>
>
>     $this->pack_start($entry1,false);
>
>     $this->expandible_spacer($this);
>
>       $vbox -> pack_start($this,0);
>
>
>
>
>
>
> }
>
>
>
>
>         function get_objs0()
>         {
>           return $this->objs0;
>         }
>
>         function get_objs1()
>         {
>           return $this->objs1;
>         }
>
>
>
> }
>
>
> //Finestra semplice e un bottone
> $objs=array();
>
> // ===========================================================
> // Creazione finestra
> $window= new GtkWindow();
> $window->connect_simple('destroy',array('Gtk','main_quit'));
> $window->set_size_request(550,400); // imposta la dimensione della finestra
>
> // Creazionne delle righe
> $vbox= new GtkVBox();
> $window-> add($vbox);
>
>
> // PROBLEM PROBLEM
> $test = New One_Label_Two_Field($vbox,"Prodotto","prod_cod","prod_descr");
> array_push($objs, $test->get_objs0());
> array_push($objs, $test->get_objs1());
>
> foreach($objs as $key=>$obj)
> {
>   is_object( $obj  )?print "This Key ".$key." IS an OBJECT \n":print " This
> Key ".$key." IS NOT AN OBJECT \n";
> }
>
> $window->show_all();
> GTK::main();
>
>
> ?>
> --
> View this message in context:
> http://www.nabble.com/Strange-result-tp20109047p20109047.html Sent from the
> Php - GTK - General mailing list archive at Nabble.com.
>
>
> --
> PHP-GTK General Mailing List (http://gtk.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


--
PHP-GTK General Mailing List (http://gtk.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

 « Return to Thread: Strange result