Re: php5: read-only variables

From: Date: Mon, 09 Feb 2004 09:33:35 +0000
Subject: Re: php5: read-only variables
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-177191@lists.php.net to get a copy of this message
Jan Lehnardt wrote: > [...] > * Constants. > > The Zend Engine 2.0 introduces per-class constants. > > Example: > > <?php > class Foo { > const constant = 'constant'; > } > > echo 'Foo::constant = ' . Foo::constant . "\n"; > ?> > > Old code that has no user-defined classes or functions > named 'const' will run without modifications. > > [...] thanks, but i think constants are not the same as readonly variables!! a constant - as the name sais - are values that should never be changed. but in my example <?php         $doc = new DomDocument();                  $root = new DomElement("root");         $root->tagName = "test"; // this, of course, doesn't work...                  print($root->tagName);         $root = $doc->appendChild($root); ?> the constructor (/another class-) function of DomElement has to set the object variable $root->tagName to "root", of course. this is why tagName isn't defined as constant... further you CAN read $root->tagName, but not set it - so it is a real READONLY variable, define in C-Code of Zend Engine... anyway, thanks a lot...

« previous php.general (#177191) next »