Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:16644 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68211 invoked by uid 1010); 13 Jun 2005 22:31:55 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 68196 invoked from network); 13 Jun 2005 22:31:55 -0000 Received: from unknown (HELO pb1.pair.com) (127.0.0.1) by localhost with SMTP; 13 Jun 2005 22:31:55 -0000 X-Host-Fingerprint: 66.11.173.122 unknown Received: from ([66.11.173.122:51008] helo=interjinn.com) by pb1.pair.com (ecelerity 1.2 r(5656M)) with SMTP id 30/CF-20931-9590EA24 for ; Mon, 13 Jun 2005 18:31:53 -0400 Received: from blobule.suds (blobule.suds [192.168.1.3]) by interjinn.com (Postfix) with ESMTP id 1A81811FB67; Mon, 13 Jun 2005 18:31:47 -0400 (EDT) To: Ron Korving Cc: internals@lists.php.net In-Reply-To: <43.34.20931.17BEDA24@pb1.pair.com> References: <5.1.0.14.2.20050603203711.028e9140@localhost> <200506051859.53976.magnus@php.net> <6E.27.21296.C90E7A24@pb1.pair.com> <38.CE.21296.BFD78A24@pb1.pair.com> <43.34.20931.17BEDA24@pb1.pair.com> Content-Type: text/plain Organization: InterJinn Message-ID: <1118701987.27553.6.camel@blobule.suds> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.5-4mdk Date: Mon, 13 Jun 2005 18:33:07 -0400 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] PHP 5.1 From: robert@interjinn.com (Robert Cummings) On Mon, 2005-06-13 at 16:23, Ron Korving wrote: > If it were possible at all to make a function accept unset variables without > generating a notice, I think ifsetor() shouldn't even be implemented. People > could then have the freedom to create such functions themselves. But > unfortunately, it doesn't seem to be possible, unless you'd suppress every > function call with a @, which I don't think is the way to go in this case. > > So if it would be possible somehow to create your own isset()-like functions > in PHP-code, I'd say implement something that would make that possible, and > ingore the whole ifsetor() discussion from that moment on. People would be > free to write whatever function they'd prefer. Voila! function ifsetordefault( $array, $key, $default=null ) { if( isset( $array[$key] ) ) { return $array[$key]; } return $default; } echo ifsetordefault( array( 1 => 'One', 2 => 'Two' ), 3, 'Three' ); Or if you prefer: function ifsetpathordefault( $array, $path, $default=null, $sep='/' ) { $pathBits = explode( $sep, $path ); $nest = $array; foreach( $pathBits as $pathBit ) { if( !isset( $nest[$pathBit] ) ) { return $default; } $nest = $nest[$pathBit]; } return $nest; } And yet, I'd still prefer an internal function to do this MUCH MUCH MUCH faster and then I'd also never need to run across the problem of naming collisions with other libraries that implement the same code :) Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------'