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

From: Date: Mon, 26 Apr 2004 10:51:00 +0000
Subject: Re: Re: How to do type/existence checking in PHP5
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-184741@lists.php.net to get a copy of this message
php-general@zirzow.dyndns.org (Curt Zirzow) writes: > 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. Good point. I missed that perspective.. > You just need: > > if (is_array($my_array) && > > is_array($my_array['some']['special']['value']['that']['i']['need']) > ) { That would make sense. Unfortunately that's not how it works. PHP5 fails on access on the second level below an actual array. Ie. the following fails on line 8. <?php $a['foo'] = 'this is not an array'; if(is_array($a) && is_array($a['foo'])) print '1'; if(is_array($a) && is_array($a['foo']['bar'])) print '2'; if(is_array($a) && is_array($a['foo']['bar']['doo'])) print '3'; if(is_array($a) && is_array($a['foo']['bar']['doo']['da'])) print '4'; ?> if I set $a['foo'] to be an object it fails on line 6, if I set it to be an integer or float it doesn't fail. I find that buggy. If it actually behaved as you stated above, I would say i'd made sense, and it would be tolerable to make applications run on PHP5. But still I agree with you in this: > I think the question is why is this a fatal error versus a simple > E_WARNING. -- ./mvh Christian Jul Jensen Frelance webprogrammer TYPO3 Typehead Denmark

« previous php.general (#184741) next »