Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:16660 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93493 invoked by uid 1010); 14 Jun 2005 12:31:21 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 93458 invoked from network); 14 Jun 2005 12:31:21 -0000 Received: from unknown (HELO hotmail.com) (127.0.0.1) by localhost with SMTP; 14 Jun 2005 12:31:21 -0000 X-Host-Fingerprint: 212.238.144.71 korving.demon.nl Received: from ([212.238.144.71:13994] helo=localhost.localdomain) by pb1.pair.com (ecelerity 1.2 r(5656M)) with SMTP id 6C/1D-20931-51ECEA24 for ; Tue, 14 Jun 2005 08:31:17 -0400 Message-ID: <6C.1D.20931.51ECEA24@pb1.pair.com> To: internals@lists.php.net 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> <1118701987.27553.6.camel@blobule.suds> <53F92510-14F5-4E4E-939F-8FC382A7B925@botimer.net> <87728790.20050613214458@ionzoft.com> <52.4A.20931.FBB6EA24@pb1.pair.com> <1118730688.27553.19.camel@blobule.suds> <42AEC486.3080408@php.net> Date: Tue, 14 Jun 2005 14:30:49 +0200 Lines: 78 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Posted-By: 212.238.144.71 Subject: Re: [PHP-DEV] PHP 5.1 From: r.korving@xit.nl ("Ron Korving") But how about this..: Let's not implement functions that do what you want to achieve, but extend PHP in whatever way necessary that would enable you to write such a function yourself? Say for example that prepending @ to function parameters would make it possible to call the function with an unset variable. Then you could write ifsetor() yourself: function ifsetor(@$var, $default) { return (isset($var)) ? $var : $default; } Someone else might prefer call by reference: function ifsetor(@&$var, $default) { if (!isset($var)) $var = $default; } And someone else might prefer using empty() : function notemptyor(@$var, $default) { return (empty($var)) ? $default : $var; } So what I would prefer is a syntax extension of some sort. The @ is just an example of course, and I'm sure it's not the prettiest way to deal with the feature, but I think implementing such a thing would be best for everybody. This way everybody can implement the ifsetor() feature in whatever way they please. It would end the whole ifsetor() discussion in this list anyway ;) Ron "Hartmut Holzgraefe" wrote in message news:42AEC486.3080408@php.net... > M. Sokolewicz wrote: > >> $x = (isset($ANY_var) ? $ANY_var : 'Default Value'); > >> by > >> $x = ifsetor($ANY_var, 'Default Value'); > >> > > I must say I fully agree; I don't see any use in putting extra functions > > in the PHP namespace just because people don't want to type a couple of > > extra characters. > > it is not "a few extra characters", its "needless duplication of characters", > and the number of characters multiplies with the number of uses of the > construct > > please keep in mind that $ANY_var can be a variable name of any length > or an element of a multidimensional array. this can leed to unreadably long > statements, hard to track down copy errors and is a maintainance nichtmare > as you always have to change things in two places at the same time > > How quick can you spot the error in the following assignment? > And if you didn't know the context: how long would it take you > to find out what it does? > > $x = (isset($config['general']['foo']['bar']['somelist']) ? $config['general']['foo']['bar']['sonelist'] : "default"); > > On the other hand the meaning of > > $x = ifsetor($config['general']['foo']['bar']['somelist'], "default"); > > is pretty clear, only about half as long and way less error prone. > > I don't really like the name 'ifsetor' but i *love* the concept and given > that there is no proper way to implement this function in user space > i'm perfectly in favor of its addition.