Re: return parse error

From: Date: Sat, 14 Apr 2001 01:08:47 +0000
Subject: Re: return parse error
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-48499@lists.php.net to get a copy of this message
Small additional info about "expression" and "language construct". Expression is anything that have value. Therefore, if language construct returns value => valid expression. Following code works: ($val) ? include('abc.php') : include('def.php'); Following code does NOT work: ($val) ? echo('abc') : echo('def'); both "include" and "echo" is language construct, but "include" returns value. Thus "include" is valid expression while "echo" is not. "return" does not return value. (It returns value to caller, but not return value for expression context) User defined functions always return value, even if there is no "return" statement => functions are always valid expression. Hope this helps. -- Yasuo Ohgaki "Jeffrey Paul" <sneak@datavibe.net> wrote in message news:5.0.2.1.2.20010413042215.02595fe8@datavibe.net... > At 03:56 AM 4/13/2001, Peter Harkins wrote: > > This generates a parse error: > > mysql_connect("localhost", "root", "rootpw") > > or > > return("bar"); > > > > But all the following work fine: > > mysql_connect("localhost", "root", "rootpw") > > or die("bar"); > > > > mysql_connect("localhost", "root", "rootpw") > > or > > print("bar"); > > > > if (!mysql_connect("localhost", "root", > > "rootpw")) { > > return("bar"); > > } > > > > Why? mysql_connect returns false on failure either way... I > > notice die > > > return isn't a function but a language construct. This is why the third > working line with the curlybraces works, and without them it doesn't. > > include() is a language construct too. the particulars of using language > constructs (like return() and include()) with control structure syntax are > explained on the page for include(). > > http://us2.php.net/manual/en/function.include.php > > -j (aka sneak) > > > > ---------------------------------------------- > sneak@datavibe.net - 0x514DB5CB > he who lives these words shall not taste death > becoming nothing yeah yeah > forever liquid cool > > > -- > 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 (#48499) next »