[PHP] Boolean-cast and arrays
First thank you all for your input on all-in-one classes. Reading the php manual on boolean types and casts, and came accros the following: quote When converting to boolean, the following values are considered FALSE: ... an array with zero elements ... /quote So here I am sitting and wondering if after all this while doing: $arr = array(); If (count($arr) == 0) {} Shouldn't have been simply doing: $arr = array(); If (!arr) {} Is the latter problematic in any programming standards? Does it take longer to process? Is it using count()? Is Type-Juggling considered good practise? Regards, Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Boolean-cast and arrays
sorry typo, make that: Shouldn't have been simply doing: $arr = array(); If (!$arr) {} -Message d'origine- De : Tim [mailto:[EMAIL PROTECTED] Envoyé : jeudi 8 février 2007 16:49 À : php-general@lists.php.net Objet : [PHP] Boolean-cast and arrays First thank you all for your input on all-in-one classes. Reading the php manual on boolean types and casts, and came accros the following: quote When converting to boolean, the following values are considered FALSE: ... an array with zero elements ... /quote So here I am sitting and wondering if after all this while doing: $arr = array(); If (count($arr) == 0) {} Shouldn't have been simply doing: $arr = array(); If (!arr) {} Is the latter problematic in any programming standards? Does it take longer to process? Is it using count()? Is Type-Juggling considered good practise? Regards, Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Boolean-cast and arrays
Tim wrote: First thank you all for your input on all-in-one classes. Reading the php manual on boolean types and casts, and came accros the following: quote When converting to boolean, the following values are considered FALSE: ... an array with zero elements ... /quote So here I am sitting and wondering if after all this while doing: $arr = array(); If (count($arr) == 0) {} Shouldn't have been simply doing: $arr = array(); If (!arr) {} I'm afraid I can't bring in any insight, I just wanted to mention that's a nice feature you've brought up. The only issue I can see popping up is that !$arr doesn't explicitly indicate that you are checking for an empty array ... Other than that, I guess it's yet another way to get of a few bytes worth of code. I'm curious to find out what others have to say. Is the latter problematic in any programming standards? Does it take longer to process? Is it using count()? Is Type-Juggling considered good practise? Regards, Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Boolean-cast and arrays
On Thu, 2007-02-08 at 18:36 +0100, Youri LACAN-BARTLEY wrote: Tim wrote: First thank you all for your input on all-in-one classes. Reading the php manual on boolean types and casts, and came accros the following: quote When converting to boolean, the following values are considered FALSE: ... an array with zero elements ... /quote So here I am sitting and wondering if after all this while doing: $arr = array(); If (count($arr) == 0) {} Shouldn't have been simply doing: $arr = array(); If (!arr) {} I'm afraid I can't bring in any insight, I just wanted to mention that's a nice feature you've brought up. The only issue I can see popping up is that !$arr doesn't explicitly indicate that you are checking for an empty array ... Other than that, I guess it's yet another way to get of a few bytes worth of code. It simplifies code and also speeds it up. Instead of incurring the cost of a function call overhead the time is instead reduced to the evaluation of an opcode. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php