Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60368 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39636 invoked from network); 30 Apr 2012 02:48:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Apr 2012 02:48:42 -0000 Authentication-Results: pb1.pair.com header.from=kris.craig@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=kris.craig@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.182 as permitted sender) X-PHP-List-Original-Sender: kris.craig@gmail.com X-Host-Fingerprint: 209.85.212.182 mail-wi0-f182.google.com Received: from [209.85.212.182] ([209.85.212.182:39590] helo=mail-wi0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FA/A6-13197-88DFD9F4 for ; Sun, 29 Apr 2012 22:48:41 -0400 Received: by wibhr14 with SMTP id hr14so2058907wib.11 for ; Sun, 29 Apr 2012 19:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=6XwlJ5ZhkKGyaxlFvsyoicYioVZP6oZn0NOaowQ52gA=; b=tpdF+Xtv5ChqxzbvJN0HZtOPdUt8DGnDTPx26n4srwCiJRELw/eLoTENJSHsVnp2YT /L7DhI+WKHFU6TLkcxV9sQXYOo60UprnwdEV+SgQiLj7uNUesZmiOAfT0lcrCrBaQJZ0 3obGZLZ7tF7TAXD5MFyA7G9Ha+Y6Vy3jJnSJR31B3509iaIPgFlhDfxY+cZXOkloNON9 88tgmiw3otnBmZuw2ssfiAYAePbFTn7Xtp+xKlX+yqmaKF6z8GJaz2gLUwyUTi3qn4YC UT0wMS7BRpaC93huIgvlc5waLQlR2xZfMB628CJXzPtLim7RlesX7A9GE0Cd6IZUQaDf 4qZQ== MIME-Version: 1.0 Received: by 10.180.79.135 with SMTP id j7mr24911538wix.19.1335754117580; Sun, 29 Apr 2012 19:48:37 -0700 (PDT) Received: by 10.223.96.129 with HTTP; Sun, 29 Apr 2012 19:48:37 -0700 (PDT) In-Reply-To: <4F9DB114.9030408@quis.cx> References: <4F9AFE3D.8010805@quis.cx> <4F9DB114.9030408@quis.cx> Date: Sun, 29 Apr 2012 19:48:37 -0700 Message-ID: To: Jille Timmermans Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=f46d04428ff4af892d04bedc7d21 Subject: Re: [PHP-DEV] Function boolval() From: kris.craig@gmail.com (Kris Craig) --f46d04428ff4af892d04bedc7d21 Content-Type: text/plain; charset=ISO-8859-1 On Sun, Apr 29, 2012 at 2:22 PM, Jille Timmermans wrote: > On 28-04-12 06:27, Kalle Sommer Nielsen wrote: > >> 2012/4/27 Jille Timmermans: >> >> I suggest we add a function boolval(). It simply converts the given >>> argument >>> to a boolean, like strval(), intval() and floatval(). I already have an >>> implementation ready[1]. >>> >>> Why? >>> * It is missing in the current list of *val()-functions and people >>> expect it >>> to exist. I'd say it is an inconsistency. >>> * It can be used as a callback, which is why a bool-cast does not >>> suffice. >>> >> >> Does it really matter nowadays when we got closures anyway: >> >> $bools = array_map(range('a', 'z'), function($a){ return((boolean) $a); >> }); >> >> Closures can achieve the same goal but are less readable as Sebastian > Krebs already pointed out and still confuses the programmer. > > > Sherif Ramadan wrote: > >> Why is this going to be more beneficial to implement? Is it that you >> feel readability of the closure is too difficult or that you feel >> there is a use case that presents further benefits for implementing a >> boolval function, beyond that of just readability or other subjective >> preferences? >> >> Personally, I would feel something like array_filter(range('a','z')); >> is way more readable than all of the above and makes a lot more sense >> to me. >> > That's just an example of course. (And doesn't even do the same thing) > > >> Under most circumstances, one does not tend to care about the truth in >> expression unless it is truth. So the following code is far more >> practical than the suggestions being made here: >> >> if (!array_filter(array(0,false,**null,'', array()))) { >> /* The array is made up entirely of falsey values */ >> } else { >> /* The array is not made up entirely of falsey values */ >> } >> >> I'm not saying the function is useless. I'm just saying PHP already >> offers more than 1,000 functions through core, alone, and adding just >> one more function that doesn't seem to offer anything new really isn't >> sounding like a promising idea to me. We only add to people's >> confusion more by offering them dozens of choices to accomplish the >> same thing. We've all heard the arguments of "print vs. echo", or X vs >> Y. There's no practical reason to include this in core being presented >> hear apart from "I like it more..." >> > I do agree it isn't perfect to have both casts and conversion functions > but we're too late now anyway. They both exist - but the boolval conversion > function is missing, which is - I think - even worse than "yet another > function". > > -- Jille +1 Please correct me if I'm mistaken, but if PHP only included functions for stuff that could not be done through some other means, we'd probably have just a small fraction of the functions we have now. Why must PHP suddenly start following such a rigid policy, and why now? Personally, I like the fact that there are multiple ways of doing things. I like the fact that PHP contains functions that are more or less abstractions meant to make my life as a developer that much easier. One of PHP's best selling points IMHO is its flexibility; that there's a function for just about everything lol. If we already have intval(), strval(), and floatval(), why must we draw a line in the sand and say that boolval() would be "one too many"?! If we want to have a conversation about re-thinking the use-cases for PHP functions, that's fine, but I honestly don't think that turning this RFC into a referendum on that is the best approach. If boolval() will further the KISS principle (think 2 parentheses instead of 8 lol), then personally I don't see what the big deal is. --Kris --f46d04428ff4af892d04bedc7d21--