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

From: Date: Mon, 15 Mar 2004 14:21:44 +0000
Subject: Re: Anyway to access a class variable without using a return function?
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-180448@lists.php.net to get a copy of this message
thank, sure. function name should be myClassGetVar() :) /tom On Mon, 15 Mar 2004 14:49:55 +0100 Marco Schuler <listworks@gmx.ch> wrote: > 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 > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php --

« previous php.general (#180448) next »