I think isset is better used when reading $_GET since there should not
be null but array_key_exists is better for later in different level
when the application can actually set null to request object.

And why shouldn't a project use both isset and array_key_exists? :)

On Thu, Sep 17, 2009 at 10:25 AM, Cliff Black <[email protected]> wrote:
>
> Interestingly enough, I've been browsing the source of Symfony some more and 
> found even they can't decide which is better: array_key_exists or isset - so 
> they use both at different levels :P
>
> From: 
> http://trac.symfony-project.org/browser/branches/1.3/lib/request/sfWebRequest.class.php
>
> 764       /**
> 765        * Returns the value of a GET parameter.
> 766        *
> 767        * @param  string $name     The GET parameter name
> 768        * @param  string $default  The default value
> 769        *
> 770        * @return string The GET parameter value
> 771        */
> 772       public function getGetParameter($name, $default = null)
> 773       {
> 774         if (isset($this->getParameters[$name]))
> 775         {
> 776           return $this->getParameters[$name];
> 777         }
> 778         else
> 779         {
> 780           return sfToolkit::getArrayValueForPath($this->getParameters, 
> $name, $default);
> 781         }
> 782       }
>
>
> <3 PHP - consistently inconsistent! :D
>
> ~ C
>
> PS: I hate ppl who reply to their own messages! :P
>
>
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of 
> Cliff Black
> Sent: Thursday, 17 September 2009 9:42 a.m.
> To: [email protected]
> Subject: [phpug] Re: PHP 5.3.0 error
>
>
> You beat me to it Sid :)
>
> Symfony definitely doesn't use the @ suppression operator.
>
> The method appears in a lot of classes - sfRequest, sfDatabase, but they all 
> are just shortcuts for $sfParameterHolder->get().
>
> Here's the source....
>
> (File: sfParameterHolder.class.php, line 43)
>  /**
>   * Retrieves a parameter.
>   *
>   * @param  string $name     A parameter name
>   * @param  mixed  $default  A default parameter value
>   *
>   * @return mixed A parameter value, if the parameter exists, otherwise null
>   */
>  public function & get($name, $default = null)
>  {
>    if (array_key_exists($name, $this->parameters))
>    {
>      $value = & $this->parameters[$name];
>    }
>    else
>    {
>      $value = sfToolkit::getArrayValueForPath($this->parameters, $name, 
> $default);
>    }
>
>    return $value;
>  }
>
> So you can clearly see, there is no @ operators.
> The 'if statement' is a longer way of writing a ternary - both have exactly 
> the same effect.
>
> ~ C
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of 
> Sid Bachtiar
> Sent: Thursday, 17 September 2009 9:26 a.m.
> To: [email protected]
> Subject: [phpug] Re: PHP 5.3.0 error
>
>
> Symfony doesn't use @ for retrieving get/post parameter, but uses it
> for database connection and other connection type as well as object
> chaining, but all these suppress errors are handled/caught somewhere
> else (e.g.:write them to log or throw them to browser on dev mode).
>
> On Thu, Sep 17, 2009 at 9:00 AM, craiganz <[email protected]> wrote:
>>
>> Hi.
>> I'll try to be more clear.  I've already posted a similar function and
>> i didn't use @ :-)
>>
>> Symfony uses the construct:
>>   @$ary[$elm];
>> within it's code -- you may or may not make use of the methods that
>> use it.  I wasn't trying to suggest @ would be used if you called
>> getParameter.
>>
>> Most of this discussion has focused on a ternary operator that returns
>> null if the array element doesn't exist.  I'm certain it's also the
>> most common use of this construct.  It just happens to be that the
>> most common use can be replaced with @ :-)
>> -Craig
>>
>> On Sep 17, 8:43 am, Sid Bachtiar <[email protected]> wrote:
>>> You just don't use @$ary[$elm] to write that kind of function since
>>> you need to detect if the index is set or not and return default value
>>> accordingly.
>>>
>>> > Of course if you use symfony, you're simply passing the use of both
>>> > this construct:
>>> >  (isset($ary[$elm])) ? $ary[$elm] : null
>>> > and this one:
>>> > �...@$ary[$elm]
>>> > to someone else's code :-)
>>>
>>> I said "I prefer $something = $request->getParameter('something');",
>>> referring to the kind of function/method/class I prefer to use.
>>>
>> >
>>
>
>
>
> --
> Blue Horn Ltd - System Development
> http://bluehorn.co.nz
>
>
>
>
>
> >
>



-- 
Blue Horn Ltd - System Development
http://bluehorn.co.nz

--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]
-~----------~----~----~----~------~----~------~--~---

Reply via email to