Re: The constant use of isset()

From: Date: Tue, 12 May 2009 17:30:35 +0000
Subject: Re: The constant use of isset()
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-43909@lists.php.net to get a copy of this message
Regarding ifsetor, what's wrong with just using this: isset($myvar) OR $myvar = 'i am set'; It works in just the same way and has no problems. I agree it would be great though if there could be a function to retrieve a variable's value if it exists, without throwing an error if it doesn't exist. I'm not sure if isset would be appropriate though. Maybe the internal implementation of array access should be changed so that a key that is not
set or has its value equal to null, should return null. This is almost the behavior we have right now: php -r "$a = array('x' => null); var_dump(isset($a['x']));" bool(false) php -r "$a = array('x' => null); var_dump($a['x']);" NULL However, the above case does not issue a notice.
Lewis. 2009/5/12 Ólafur Waage<olafurw@gmail.com>:
While researching for this suggestion I found this rfc proposal regarding ifsetor() ( http://wiki.php.net/rfc/ifsetor?s[]=isset<http://wiki.php.net/rfc/ifsetor?s%5B%5D=isset>) and it's rejection point was that it was currently not possible ( http://marc.info/?l=php-internals&m=108931281901389&w=2 ) But would it be possible to check for a value of a variable if it is set? Since I often do (and see others do) if(isset($_GET["foo"])&& $_GET["foo"] == "bar") or even worse if((isset($_GET["foo"])&& $_GET["foo"] == "bar") || (isset($_GET["baz"])&& $_GET["baz"] == "bat")) to be able to do something like this if(isset($_GET["foo"]) == "bar") or if(isset($_GET["foo"]) == "bar" || isset($_GET["baz"]) == "bat") That isset (or some other language construct) would return the variable if it were set and false if it was not. Thanks for your time, i know this has probably been talked to death in one form or other. Ólafur Waage olafurw@gmail.com
     
-- Ionut G. Stan I'm under construction | http://igstan.blogspot.com/

« previous php.internals (#43909) next »