Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60437 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68029 invoked from network); 3 May 2012 18:11:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 May 2012 18:11:06 -0000 Authentication-Results: pb1.pair.com header.from=patrick.allaert@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=patrick.allaert@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.170 as permitted sender) X-PHP-List-Original-Sender: patrick.allaert@gmail.com X-Host-Fingerprint: 209.85.213.170 mail-yx0-f170.google.com Received: from [209.85.213.170] ([209.85.213.170:59756] helo=mail-yx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 40/E3-41225-93AC2AF4 for ; Thu, 03 May 2012 14:11:06 -0400 Received: by yenl5 with SMTP id l5so2294455yen.29 for ; Thu, 03 May 2012 11:11:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=O0sXckASyAZcqHycSdO80adN6Wb7MW3aOzBYN1++hf4=; b=PFQmQu5ua/Ez5tlV28GJSJgxocnB4cxtRlyen1YSSSpv30BYjd6GIY1rNhMA94WEHi b+aBASbqzFS7Qry5tjVlm39gJl+SeM3MocfvRg1KOg4pGH7POEsYfhc4qaohIWvyPden ZZnuBIkT4TD77KpNhGDYPT2/fWW2AcLjv5Wry44/Pz5S4K9UjpOxOwfJcS0uChCEkChz FvKRCxmK3SqnKSxv1RzgQnVPFaadXy/XUinpG+8NSOmWXzqKUigf994P3hausPtSzKbT cdISSgnkBHKV5RnbXNs9QfkjHd/UaoaagWiBSZsNRYTepzVrNZjk2Ke7p7vm9LSNkQbB whEw== MIME-Version: 1.0 Received: by 10.68.136.65 with SMTP id py1mr10093935pbb.81.1336068659692; Thu, 03 May 2012 11:10:59 -0700 (PDT) Sender: patrick.allaert@gmail.com Received: by 10.68.50.104 with HTTP; Thu, 3 May 2012 11:10:59 -0700 (PDT) In-Reply-To: <4FA23115.9030807@lsces.co.uk> References: <4FA23115.9030807@lsces.co.uk> Date: Thu, 3 May 2012 20:10:59 +0200 X-Google-Sender-Auth: fryMiIdSLrxm7662nFU51he4iw8 Message-ID: To: Lester Caine Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Allow non-variable arguments to empty() and isset() From: patrickallaert@php.net (Patrick ALLAERT) 2012/5/3 Lester Caine : > Anthony Ferrara wrote: >> >> I voted for the ability to use an expression for isset() as well, >> since I agree with Ferenc, it's a matter of consistency. =C2=A0Sure, the >> use-case for isset() is definitely weaker than for empty(), but at the >> same token they are definitely related... > > > I just can't help feeling that it is the wrong use of both. If the functi= on > is returning a value, then it's returning a value that needs to be used > somewhere so the work flow handles that. If the function returns nothing > instead that just seems wrong and needs to be handled better. I'm used to > getting back 'false' if the function failed and just check for that so wh= y > would there be any logical reason for using isset or empty to check a > function return? Use case: // Function definition: function getFriends() { // SQL SELECT or Fetching from XML or Fetching from LDAP or ... return $resultsAsArray; } // Looping on results: foreach ( getFriends() as $friend ) { echo $friend["name"], "\n"; } // Case where the results are actually not iterated: $amIAssocial =3D empty( getFriends() ); 1. It it not wrong to return "nothing", like empty sets (empty arrays), it is a valid case. 2. Returning "false" in the case there is no "results" would be a bad idea: not only you would have to put a condition in the function definition, but you would also require all iterations (e.g. foreach) to be encapsulated in a condition statement to prevent looping on "false".