Re: [PHP] Two very useful PHP functions
On Fri, May 1, 2009 at 4:05 AM, Darren wrote: > This was discussed for PHP6, but eventually decided not to have such a > function. Instead, we now have the following: $var = $_GET['var'] ?: 5; > > Taken from http://www.corephp.co.uk/archives/19-Prepare-for-PHP-6.html > > 'you'd be able to do something like this: "$foo = $_GET['foo'] ?: 42;" (i.e. > if foo is true, $foo will equal 42).' > > I don't like that syntax at all. You would have to scrutinize code even more to determine whether a statement like this was intentional or a botched ternary operator. I'm not sure there is a need for a function like ifset/ifsetor, but I'd MUCH rather have a clear function name that could easily be found in the manual than mangling the ternary operator. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Two very useful PHP functions
This was discussed for PHP6, but eventually decided not to have such a function. Instead, we now have the following:$var = $_GET['var'] ?: 5; Taken from http://www.corephp.co.uk/archives/19-Prepare-for-PHP-6.html 'you'd be able to do something like this: "$foo = $_GET['foo'] ?: 42;" (i.e. if foo is true, $foo will equal 42).' 2009/5/1 Raymond Irving > > Hi Colin and Daniel, > > Thanks for the feedback. > > I know that this functionality can be added to a framework or a stand alone > function but I'm assuming that we would not get the same performance: > > Case 1 > --- > $c = isset($a) ? $a : ''; > // total time = overhead of isset() + overhead of ?: > > Case 2 > --- > $c = myWrapper($a,$b) > // total time = overhead of myWrapper() + overhead of isset() + overhead of > ?: > > Case 3 > --- > $c = ifset($a,$b) > // total time = overhead of ifset() > > > > Best regards > > __ > Raymond Irving > > --- On Thu, 4/30/09, Daniel Brown wrote: > > > From: Daniel Brown > > Subject: Re: [PHP] Two very useful PHP functions > > To: "Raymond Irving" > > Cc: php-general@lists.php.net > > Date: Thursday, April 30, 2009, 11:37 AM > > On Wed, Apr 29, 2009 at 22:32, > > Raymond Irving > > wrote: > > > > > > What do you think? Can they make it into 5.3? > > > > Not when doing the ternary operator that you > > even displayed > > yourself takes up less code and time than a core function > > would. It's > > a good idea, but better handled on the frontend of > > things. You may > > want to consider contributing that to a framework, which is > > where it > > would be more appropriate. > > > > -- > > > > daniel.br...@parasane.net > > || danbr...@php.net > > http://www.parasane.net/ || http://www.pilotpig.net/ > > 50% Off All Shared Hosting Plans at PilotPig: Use Coupon > > DOW1 > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] Two very useful PHP functions
Hi Colin and Daniel, Thanks for the feedback. I know that this functionality can be added to a framework or a stand alone function but I'm assuming that we would not get the same performance: Case 1 --- $c = isset($a) ? $a : ''; // total time = overhead of isset() + overhead of ?: Case 2 --- $c = myWrapper($a,$b) // total time = overhead of myWrapper() + overhead of isset() + overhead of ?: Case 3 --- $c = ifset($a,$b) // total time = overhead of ifset() Best regards __ Raymond Irving --- On Thu, 4/30/09, Daniel Brown wrote: > From: Daniel Brown > Subject: Re: [PHP] Two very useful PHP functions > To: "Raymond Irving" > Cc: php-general@lists.php.net > Date: Thursday, April 30, 2009, 11:37 AM > On Wed, Apr 29, 2009 at 22:32, > Raymond Irving > wrote: > > > > What do you think? Can they make it into 5.3? > > Not when doing the ternary operator that you > even displayed > yourself takes up less code and time than a core function > would. It's > a good idea, but better handled on the frontend of > things. You may > want to consider contributing that to a framework, which is > where it > would be more appropriate. > > -- > > daniel.br...@parasane.net > || danbr...@php.net > http://www.parasane.net/ || http://www.pilotpig.net/ > 50% Off All Shared Hosting Plans at PilotPig: Use Coupon > DOW1 > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Two very useful PHP functions
On Wed, Apr 29, 2009 at 22:32, Raymond Irving wrote: > > What do you think? Can they make it into 5.3? Not when doing the ternary operator that you even displayed yourself takes up less code and time than a core function would. It's a good idea, but better handled on the frontend of things. You may want to consider contributing that to a framework, which is where it would be more appropriate. -- daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ 50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Two very useful PHP functions
Hello, Every so often I have to be using the isset() function to check if a variable exists. It would be useful to have something like an ifset() function Instead of doing this $v = isset($input) ? $input : $default; we can do this $v = ifset($input,$default); // returns $input if it exists otherwise it will return $default We could also do the same for the empty() function. So instead of doing this $v = empty($input) ? $default : $input; we can do this $v = ifempty($input,$default); // returns $input if it is not empty otherwise it will return $default What do you think? Can they make it into 5.3? Best regards __ Raymond Irving