Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51863 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3471 invoked from network); 11 Apr 2011 13:38:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Apr 2011 13:38:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=etienne@immomigsa.ch; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=etienne@immomigsa.ch; sender-id=unknown Received-SPF: error (pb1.pair.com: domain immomigsa.ch from 94.103.100.39 cause and error) X-PHP-List-Original-Sender: etienne@immomigsa.ch X-Host-Fingerprint: 94.103.100.39 mailer.immomigsa.ch Linux 2.6 Received: from [94.103.100.39] ([94.103.100.39:52918] helo=mailer.immomigsa.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FF/6A-29000-F4403AD4 for ; Mon, 11 Apr 2011 09:38:24 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by mailer.immomigsa.ch (Postfix) with ESMTP id 65C5E4B60E82; Mon, 11 Apr 2011 15:38:20 +0200 (CEST) X-Virus-Scanned: amavisd-new at immomigsa.ch Received: from mailer.immomigsa.ch ([127.0.0.1]) by localhost (mailer.immomigsa.ch [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ylRiQGCVg4Ce; Mon, 11 Apr 2011 15:38:20 +0200 (CEST) Received: from crousti (tsf-wpa-2-7250.epfl.ch [128.178.247.250]) by mailer.immomigsa.ch (Postfix) with ESMTPSA id 084B44B60E4F; Mon, 11 Apr 2011 15:38:19 +0200 (CEST) Received: by crousti (sSMTP sendmail emulation); Mon, 11 Apr 2011 15:36:57 +0200 Date: Mon, 11 Apr 2011 15:36:57 +0200 To: "D. Dante Lorenso" Cc: Internals Mailing List Message-ID: <20110411133657.GK7113@crousti> References: <4DA26602.6080303@lorenso.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4DA26602.6080303@lorenso.com> User-Agent: Mutt/1.5.20 (2009-06-14) Subject: Re: [PHP-DEV] proposed access modifier "silent" ... was: Re: [PHP-DEV] Implicit isset/isempty check on short-ternary operator From: etienne@immomigsa.ch (Etienne Kneuss) On Apr 10 21:22:58, D. Dante Lorenso wrote: > The problem with implementing "ifsetor", "filled", or "??" in userland > is that the "not set" or "undefined" warning is fired before the > variable is passed to the underlying function/method. > > Is it possible to add a modifier that turns off warnings for undefined > variables whenever that specific method is called? Something like: Short answer is no. See below. > > class Utility { > public silent function filled() { > $args = func_get_args(); > foreach ($args as $arg) { > if (!empty($arg)) { return $arg; } > } > return false; > } > } > > $x = Utility::filled($my_undef, $x['undef'], $nosuch, 'default'); > > The modifier "silent" will turn all undefined or "not isset()" variables > into NULL values when being passed to the method and no warnings will be > issued. This is not really possible without some major changes. You've to understand that arguments are evaluated before the function/method call. The notices are thus emited before even considering the function/method call. This is exactly why isset and empty are not functions, but language constructs, so that they can work with variables in a special way. > > Then, we can build our own damn functions as we see fit without the fuss. > > -- Dante > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >