Re: Re: How to do type/existence checking in PHP5

From: Date: Fri, 23 Apr 2004 15:25:29 +0000
Subject: Re: Re: How to do type/existence checking in PHP5
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-184402@lists.php.net to get a copy of this message
* Thus wrote Christian Jul Jensen (christian@jul.net): > > Hi > > Thanks for taking time to look into this. > > redeye@erisx.de (Red Wingate) writes: > > > > this is a plain design fault on your side: > > I'm sorry, but I don't agree. It is standard in PHP4, and one of the > advantages of having a type loose programming language. Perhaps you misunderstand the 'loose' part of the variables, basically there are 4 types of variables: 1. scalar 2. array 3. object 4. resource How you can access each one differs. > > > Now this makes sense as you first of all would make sure if $a is an > > array and not start with the first index ( which doesn't exist as $a > > is not even an array ) > > > in PHP5, in order not to risk a fatal error, this would have to be: > > $my_array = $some_weird_function_that_returns_a_multidim_array(); > if( is_array($my_array['some']) && > is_array($my_array['some']['special']) && > is_array($my_array['some']['special']['value']) > && > > is_array($my_array['some']['special']['value']['that']) > && > > is_array($my_array['some']['special']['value']['that']['i']) > && > > is_array($my_array['some']['special']['value']['that']['i']['need']) > ) { > apply_logic(); > } You just need: if (is_array($my_array) && is_array($my_array['some']['special']['value']['that']['i']['need']) ) { > > I find this to be a problem, because it makes it hard to migrate > scripts from PHP4, and I'd rather spend my time using the new object > model and XML support, than going through old scripts to make sure > they comply with a new behaviour which I see no good reason for. I think the question is why is this a fatal error versus a simple E_WARNING. Curt -- "I used to think I was indecisive, but now I'm not so sure."

« previous php.general (#184402) next »