Re: variable functions: empty/isset/unset invalid?

From: Date: Mon, 07 May 2001 19:42:37 +0000
Subject: Re: variable functions: empty/isset/unset invalid?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-51806@lists.php.net to get a copy of this message
> Thanks for the additional code, now I see what you are after. Sorry, I don't > know the answer, other than using curly braces will fix the problem for > empty(). Also, a User Contributed Note at > > http://www.php.net/manual/en/functions.php#functions.user-defined > has this > to say: > > <quote> > there are tons of good uses for this sort of functionality. But it should be > noted that this will not work with > include() > include_once() > require() > require_once() > > it's safe to assume that this is for safty. > </quote> These funtions are directives rather than normal php functions as the manual says. I'm just guessing, maybe empty(), isset() and other variable-testing functions are also directives with a function-syntax wrapper and this is the reason why PHP doesn't find them as functions (not in the target-list :). > > Kirk > > > -----Original Message----- > > From: Philip Olson [mailto:philip@cornado.com] > > Sent: Monday, May 07, 2001 11:45 AM > > To: php-general@lists.php.net > > Subject: RE: [PHP] variable functions: empty/isset/unset invalid? > > > > > > > > I wish it were that easy. Also, I'm looking for words on WHY this > > behavior exists. > > > > > > http://www.php.net/manual/en/functions.variable-functions.php > > > > <?php > > > > // works > > if (empty($var)) print '$var is empty<br>'; > > > > // works > > $foo = 'is_string'; > > $var = 'abcdef'; > > if ($foo($var)) print '$var is a string<br>'; > > > > // works > > $foo = 'strlen'; > > $var = 'abcdef'; > > if ($foo($var) > 5) print '$var is over 5 chars<br>'; > > > > // doesn't work : Fatal Error : Call to undefined function: empty() > > // same with isset() and unset() > > $foo = 'empty'; > > if ($foo($var)) print '$var is empty'; > > > > ?> > > > > In otherwords, only these few functions aren't working as "variable > > functions" but result in a "Fatal Error" instead. Why? > > > > > > Regards, > > Philip > > > > On Mon, 7 May 2001, Johnson, Kirk wrote: > > > > > Change the parens around $var to curly braces: > > > > > > if ($foo{$var}) print 'worked.'; > > > > > > Kirk > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#51806) next »