Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:16661 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4780 invoked by uid 1010); 14 Jun 2005 13:00:45 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 4765 invoked from network); 14 Jun 2005 13:00:45 -0000 Received: from unknown (HELO artweb-design.de) (127.0.0.1) by localhost with SMTP; 14 Jun 2005 13:00:45 -0000 Received: from ([127.0.0.1:18887]) by pb1.pair.com (ecelerity 1.2 r(5656M)) with ECSTREAM id A4/FD-20931-DF4DEA24 for ; Tue, 14 Jun 2005 09:00:45 -0400 X-Host-Fingerprint: 217.160.143.66 thelema-society.de Linux 2.4/2.6 Received: from ([217.160.143.66:56233] helo=p15114004.pureserver.info) by pb1.pair.com (ecelerity 1.2 r(5656M)) with SMTP id D7/9D-20931-191DEA24 for ; Tue, 14 Jun 2005 08:46:10 -0400 Received: from SVENSCOMPUTER (pD9FB1D3A.dip0.t-ipconnect.de [217.251.29.58]) by p15114004.pureserver.info (Postfix) with ESMTP id A0C8D1CF434; Tue, 14 Jun 2005 14:46:05 +0200 (CEST) Date: Mon, 13 Jun 2005 22:56:03 +0200 X-Mailer: The Bat! (v3.5) UNREG / CD5BF9353B3B7091 Reply-To: Sven Fuchs X-Priority: 3 (Normal) Message-ID: <177634065.20050613225603@artweb-design.de> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re[2]: [PHP-DEV] PHP 5.1 From: svenfuchs@artweb-design.de (Sven Fuchs) Why isn't is possible in userland? Is there any problem with using this? function ifsetor(&$var, $default = null) { return isset($var) ? $var : $default; } echo ifsetor($a, 'foo'); echo $a, $b; echo ifsetor($a, 'foo'); echo isset($a) ? 'is set' : 'not set'; expected result: foo Notice: Undefined variable: a in [...] Notice: Undefined variable: b in [...] foo not set actual result: foo Notice: Undefined variable: b in [...] foo not set php does not issue a notice on using $a after having called ifsetor() once. But further calls to isset() and ifsetor() keep returning the expected results. I'd assume, the missing notice is rather a bug than a feature. So ifsetor() is possible in userland. -- Sven > 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. > Ron > ""Sara Golemon"" wrote in message > news:38.CE.21296.BFD78A24@pb1.pair.com... >> > > What about ifsetor for 5.1 ? >> > >> > Would anybody be interested in a parameter for ifsetor() that would > treat >> > isset() as !empty() or an alternative function that achieves this? I > know >> > I'd love to see that. I use empty() a lot more than isset(). >> > >> In the interrest of KISS, I'd leave the emptiness concept out of the >> picture. Unlike isset-ness, an emptiness coalesce *can* be done in >> userspace: >> >> function firstNotEmpty() { >> $vars = func_get_args(); >> foreach($vars as $var) >> if (!empty($var)) return $var; >> return NULL; >> } >> >> There's enough....contention over the undeniably useful and >> not-implementable-in-userspace parts of this thread that it's not worth >> muddling it up with things that are a simple matter to do in userspace. > It >> doesn't matter that notempty() and ifsetor() could easily be implemented > by >> the same opcode (just like isset/empty are). >> >> -Sara