Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86768 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 40294 invoked from network); 21 Jun 2015 18:44:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Jun 2015 18:44:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.181 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.212.181 mail-wi0-f181.google.com Received: from [209.85.212.181] ([209.85.212.181:38291] helo=mail-wi0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CB/02-29062-91607855 for ; Sun, 21 Jun 2015 14:44:42 -0400 Received: by wibdq8 with SMTP id dq8so56999365wib.1 for ; Sun, 21 Jun 2015 11:44:39 -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=/l6rp8CWuR/oRolPwv+1KmmZNW8qrzbpNe7yqyXETS8=; b=0TUDibLWX429/m50iiXwQwZzsq0iC7RRKS1aHIl5lbQdGZ4t6BVgiTFHumbZf5ptQX OC5fV/hMci4Ik0qJTfSxTIvdYzsvQ2ciIGyKgY5jgfVvGO7lQHI+Ny4k/OR3fnsR7xLg xG8uF9E0ksalpo7r0R+6/1OQvCFRBAcVHVJIIm+yqBTGBuKMG856LYbV+Jx9gs1nloJ4 oQR6ozDQKzjWkI5j+S+TK/2QPaZuXEnWlGPREzdP839fPSJbtMusrWHsp6LFHgzVDe8P cFFYIK5LVLBqP3EkxhULD3/YH2jVF89WS0z2olLjO3sHSOjylhQHs0ii4bXdJj8sde6H a3eQ== MIME-Version: 1.0 X-Received: by 10.194.97.196 with SMTP id ec4mr45238292wjb.3.1434912279316; Sun, 21 Jun 2015 11:44:39 -0700 (PDT) Received: by 10.27.179.96 with HTTP; Sun, 21 Jun 2015 11:44:39 -0700 (PDT) In-Reply-To: <5586E5D1.4010901@lerdorf.com> References: <5586E5D1.4010901@lerdorf.com> Date: Sun, 21 Jun 2015 20:44:39 +0200 Message-ID: To: Rasmus Lerdorf Cc: PHP internals Content-Type: multipart/alternative; boundary=047d7bf0ef18b1503c05190b8ce4 Subject: Re: [PHP-DEV] hasType() for internal function parameters? From: nikita.ppv@gmail.com (Nikita Popov) --047d7bf0ef18b1503c05190b8ce4 Content-Type: text/plain; charset=UTF-8 On Sun, Jun 21, 2015 at 6:26 PM, Rasmus Lerdorf wrote: > Is it deliberate that we are not providing the parameter types for > internal functions via reflection? It seems inconsistent: > > declare(strict_types=1); > function ustrlen(string $str) { } > $param_ustrlen = (new > ReflectionFunction('ustrlen'))->getParameters()[0]; > $param_strlen = (new ReflectionFunction('strlen'))->getParameters()[0]; > > echo "$param_ustrlen (".$param_ustrlen->hasType().")\n"; > echo "$param_strlen (".$param_strlen->hasType().")\n"; > > try { > ustrlen(1); > } catch (TypeError $e) { > echo $e->getMessage()."\n"; > } > > try { > strlen(1); > } catch (TypeError $e) { > echo $e->getMessage()."\n"; > } > > The output is: > > Parameter #0 [ string $str ] (1) > Parameter #0 [ $str ] () > Argument 1 passed to ustrlen() must be of the type string, integer > given, called in /home/rasmus/prop.php on line 11 > strlen() expects parameter 1 to be string, integer given > > That is, in both cases a TypeError exception is raised because the type > of the parameter is incorrect. But hasType() on the internal function > parameter claims there is no type even though there obviously is one. > > -Rasmus > The difference here is that ustrlen() has an argument type specified in arginfo, while strlen() triggers an error through zend_parse_parameters(). We have practically no arginfo-level type annotations in the standard library. Nikita --047d7bf0ef18b1503c05190b8ce4--