Re: Anyway to access a class variable without using a return function?

From: Date: Mon, 15 Mar 2004 13:49:55 +0000
Subject: Re: Anyway to access a class variable without using a return function?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-180446@lists.php.net to get a copy of this message
Hi Am Mo, 2004-03-15 um 14.10 schrieb Tom Meinlschmidt: > I mean using get_object_vars() is much better. > > and in the example I've seen there: > > you HAVE TO define all the variables you're using in a class scope. eg > class myClass { > var $var1; > var $var2 = array(); > > function myClass($var) { > $vars =get_object_vars($this); > if (isset($vars[$var])) return $vars[$var]; > return false; > } > } Somewhat more elegant, yes. But: your function above is called myClass which is the classname and therefore this function is a _constructor_! As a constructor does not allow to return values, the above example would only work if you rename the function-name to something other than myClass! -- Regards Marco

« previous php.general (#180446) next »