Re: class variable shared by all objects

From: Date: Thu, 17 Oct 2002 05:58:12 +0000
Subject: Re: class variable shared by all objects
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-120284@lists.php.net to get a copy of this message
You can use this function : get_object_vars to retreive vars from a class.. Here is the example from phpdoc : <?php class Point2D { var $x, $y; var $name; function Point2D($x, $y) { $this->x = $x; $this->y = $y; } function setName($name) { $this->name = $name; } function ReadPoint() { return array("x" -> $this->x, "y" -> $this->y, "name" -> $this->name); } } $p1 = new Point2D(1.233, 3.445); print_r(get_object_vars($p1)); // "$nom" is declard but undefined // Array // ( // [x] -> 1.233 // [y] -> 3.445 // ) $p1->setName("point #1"); print_r(get_object_vars($p1)); // Array // ( // [x] -> 1.233 // [y] -> 3.445 // [name] -> point #1 // ) ?>"Christophe Barbe" <christophe.barbe@ufies.org> a écrit dans le message de news: 20021016202143.GA5600@cattlegrid.net... > I guess the answer is obvious but can't find it in the manual. > > Is it possible to have a variable in a class that is shared by all > instances. I thought 'static' would do it but apparently not. > > Christophe > > -- > Christophe Barbé <christophe.barbe@ufies.org> > GnuPG FingerPrint: E0F6 FADF 2A5C F072 6AF8 F67A 8F45 2F1E D72C B41E > > Dogs believe they are human. Cats believe they are God.

« previous php.general (#120284) next »