NYCPHP Meetup

NYPHP.org

[nycphp-talk] Accessing non-existent array elements ok?

Kenneth Downs ken at secdat.com
Mon Aug 18 13:09:18 EDT 2008


David Mintz wrote:
>
>
> On Mon, Aug 18, 2008 at 8:51 AM, Kenneth Downs <ken at secdat.com 
> <mailto:ken at secdat.com>> wrote:
>
>
>     function a(&$array, $key,$default='') {
>      if (isset($array[$key])) return $array[$key];
>      else return $default;
>     }
>
>     This allows you to code up simpler unconditional routines with
>     code like:
>
>     $value = a($myArray,$key,'AccetableDefault');
>
>
>
> Does using an array reference &$array buy you anything in this instance?

The basic idea is you don't know how big the array is and you don't want 
to pass anything more than you want to.

I first coded the routine in PHP 4.x, when you had to be pretty explicit 
about these things.  I have not followed up in awhile so I can't tell 
you if you still need the explicit by-reference operator, but it can't hurt.



>  
>
> -- 
> David Mintz
> http://davidmintz.org/
>
> The subtle source is clear and bright
> The tributary streams flow through the darkness
> ------------------------------------------------------------------------
>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php


-- 
Kenneth Downs
Secure Data Software, Inc.
www.secdat.com    www.andromeda-project.org
631-689-7200   Fax: 631-689-0527
cell: 631-379-0010

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20080818/8cbd4cc4/attachment.html>


More information about the talk mailing list