|  | Posted by Jerry Stuckle on 06/19/40 11:44 
Oli Filth wrote:> Jerry Stuckle said the following on 09/04/2006 02:53:
 >
 >> Oli Filth wrote:
 >>
 >>> Jerry Stuckle said the following on 08/04/2006 21:51:
 >>>
 >>>> Oli Filth wrote:
 >>>>
 >>>>> function getWithDefault(&$array, $key, $default = NULL)
 >>>>> {
 >>>>>     return (isset($array[$key])) ? $array[$key] : $default;
 >>>>> }
 >>>>>
 >>>>>
 >>>>
 >>>> And if $array is empty you get a warning.
 >>>>
 >>>
 >>> You do?  I don't.  Nor can I see any reason why one should get a
 >>> warning.  What version of PHP are you running?
 >>>
 >>
 >> Try turning on all warnings.
 >
 >
 >
 > I have error level set to E_ALL | E_STRICT.  The following code executes
 > fine:
 >     <?php
 >
 >     function getValueWithDefault(&$array, $key, $default = NULL)
 >     {
 >         return (isset($array[$key])) ? $array[$key] : $default;
 >     }
 >
 >     $var = array();
 >     echo getValueWithDefault($var, "Roger", "Dodger") . "\n";
 >
 >     ?>
 >
 > I see no reason why an error/warning should get thrown.  isset() simply
 > looks for an element with the specified key name in the associative
 > array.  In an empty array, the key doesn't exist, so isset() returns false.
 >
 
 
 That's not what I said.  I said if $var is EMPTY.
 
 Take out the $var=array() line and see what you get.
 
 
 --
 ==================
 Remove the "x" from my email address
 Jerry Stuckle
 JDS Computer Training Corp.
 jstucklex@attglobal.net
 ==================
  Navigation: [Reply to this message] |