Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93776 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96434 invoked from network); 4 Jun 2016 19:26:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jun 2016 19:26:30 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.213.46 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.213.46 mail-vk0-f46.google.com Received: from [209.85.213.46] ([209.85.213.46:34214] helo=mail-vk0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 39/79-25194-56B23575 for ; Sat, 04 Jun 2016 15:26:29 -0400 Received: by mail-vk0-f46.google.com with SMTP id e4so18452182vkb.1 for ; Sat, 04 Jun 2016 12:26:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindplay-dk.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=bTkHPfHfG/tNAGWG9nASRdvgwmDlZ+uShgwvun1B0kU=; b=1sVRFc+HxdlDLPsgiTrZ2Au+yVTjgIZTaW7/ZHF9zsuzz7Ex5OO4UbE4zp7yxZJKv+ RDcviY5XoWH/mFwj13h2LmvpdlG1hHY5PZwRzLOkBy7g4NzUvFfuhtyb6nGTBhQE2xSU 0B7T6z2q+ahhKCFn53TMwvnLgB/MoJS9iphoZ+70Gob9X28QQcz28k9LomwrYCsWcVPu G6yd8rvr/bn67si4iAGrk5A9HUJUi3zyhWGwBQBEJotHAZNDpli4HRdDFKoaug2zka4H nMxgnKRH5+pC5UPPI+FZhpnkvnwdfN0DDLdyu+RY4v/VaTVw82jrP4lLLTLPMQOn88TO 1pbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=bTkHPfHfG/tNAGWG9nASRdvgwmDlZ+uShgwvun1B0kU=; b=LIAg/udMvGwnxnYiHE6MGNnFmmxJr/avIajPqbs+7Vb5izEH0PG4ee5ZcUwF7E2bwU u+T+6M07N7LBFgHv9hbftx7NvIt34t5uU1rJ+rOyOQtgDkV23ZeaOXjYgABQ7PtK9yiL B+BG/2PsbjvKZmrGFlnVl4rfmlfLflGIycNMeSs/2+5iazAi22F92giRV5HTO61ldZgH S43sOB4ZZvZASqMeABAGylVY35WGdPHfTtfAXMTcmdCQ4wgl1Onj80jQgYRjxm4FfPXO WgO2nAyaSnOqXbkFOMska616B/J+7wOdDxeC46wIvZcV2rc50l4wbOvP5XttW3FNReIz /wIQ== X-Gm-Message-State: ALyK8tJpCaxtUMLaHWapO7KIBk07vxdf61zCbrElnVmWRplOYBSVCE2SGuM/31qTyWv894Ta0A3TYpT2rYx83A== X-Received: by 10.31.181.83 with SMTP id e80mr3909501vkf.26.1465068386367; Sat, 04 Jun 2016 12:26:26 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.76.200 with HTTP; Sat, 4 Jun 2016 12:26:25 -0700 (PDT) In-Reply-To: References: Date: Sat, 4 Jun 2016 21:26:25 +0200 Message-ID: To: Sara Golemon Cc: PHP internals Content-Type: multipart/alternative; boundary=001a1143a68cbdd52c053478d0bd Subject: Re: [PHP-DEV] [RFC DISCUSSION] typeof From: rasmus@mindplay.dk (Rasmus Schultz) --001a1143a68cbdd52c053478d0bd Content-Type: text/plain; charset=UTF-8 > My number one issue with this PR is that it's all PHP code. There's nothing in here that couldn't be done as a composer installable library It's a valid point, but not really a good argument against having it - the same could after all be said about a lot of PHP functions. The problem is that gettype() has numerous inconsistencies with the language - since we can't fix gettype() without causing serious BC breaks, I think that we do need this up-to-date function. (in fact, I would encourage you to think about deprecating gettype, but that's probably a discussion for another day.) Also, this should be easy to polyfill for PHP < 7.1, correct? It's harder to argue the same for the human-readable function, but I do think it would be pretty great if we had this - people wouldn't think twice about using it to generate more helpful and friendly exception messages, and that's a good thing for the language overall. As for a third-party dependency (such as my library) people will always think twice before installing that *just* to produce better exception messages - I wrote the thing, and even *I* think twice before I add that as a dependency. On Sat, Jun 4, 2016 at 7:37 PM, Sara Golemon wrote: > On Sat, Jun 4, 2016 at 5:12 AM, Fleshgrinder wrote: > > I prepared my first contribution to internals: > > > Welcome! > > > https://github.com/php/php-src/pull/1932 > > > I've put a couple minor notes on the implementation. Nothing > technically wrong, just style and micro-perf. > > > I would like to discuss the proposed new function here. > > > My number one issue with this PR is that it's all PHP code. There's > nothing in here that couldn't be done as a composer installable > library wrapping the existing gettype() and mapping around the > oddities you mention in the RFC. Wouldn't it be better to make > something that'll work across PHP versions, rather than something only > available in 7.1? > > Beyond that, though on a similar vein, the extended format feels like > unparsable overkill for any use case but logging, and in the case of > logging you probably want the value as well which calls for something > more in the var_*() family. var_describe, perhaps? > > By comparison, when it comes to code logic, there's nothing I do with > (typeof($foo, true) === 'bool true') that I can't do with > ((gettype($foo) === 'boolean') && $foo). I'll grant that the former > is marginally more readable, but only in the most generous, liberal > sense. > > If you'd like a new typeof() function, I think we should design it to > be much more robust like what Marco suggested. I don't care if that's > ReflectionType or ReflectionVariable or ReflectionBananaForScale. > Something that serves both programmatic needs by having ->isCallable() > ->isNumeric() etc methods *and* serves human readability through a > __toString() method seems to make much more sense. > > Lastly, with all the work going into gradual typing, I can see us > specifically wanting the name `typeof` at some later point. So at the > VERY least, I'd rename this to var_type() or similar. > > -Sara > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --001a1143a68cbdd52c053478d0bd--