Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79649 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67766 invoked from network); 14 Dec 2014 21:20:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Dec 2014 21:20:39 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.43 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.43 mail-wg0-f43.google.com Received: from [74.125.82.43] ([74.125.82.43:46672] helo=mail-wg0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9B/D1-57297-62FFD845 for ; Sun, 14 Dec 2014 16:20:39 -0500 Received: by mail-wg0-f43.google.com with SMTP id l18so13194496wgh.16 for ; Sun, 14 Dec 2014 13:20:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=gbcL+n5i4sfhGL5yanL9yQ/D6fBRTTTBSCG//P+gIUI=; b=ovMRfsBd1yBQvnWbQ3Y98BuPYsvbXU7g/M0ySbYz4e76z/tMMklGhqrbwGRznj9795 +KVQt5P1XATD0lTxjJTyzbkwYz3JioFCN2Lhx0EH0uNo6VpjC5OV7QnNC5FoeYrFxXL0 c92/SLlqC+Fj1COA8TFCevNd/MH0oV7GMV9HKYzWgu3oad82n9ffAYS8SrxmKkKz8luz xup5iCxGyDWiczxBIrp2wwOJmptPe24DXFsHgWEOJ2vJtAUJHXPPzWyZGd73BXVgBkC0 OhpuDsPmKd7vYnSPTQF7WrQEX9v7vgWlx78LiHAV5eubMur+lzwdvQj+++N/CXNB9ntU hVTQ== X-Received: by 10.194.6.7 with SMTP id w7mr45371465wjw.25.1418592035823; Sun, 14 Dec 2014 13:20:35 -0800 (PST) Received: from [192.168.0.2] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id h14sm10795061wic.8.2014.12.14.13.20.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Dec 2014 13:20:35 -0800 (PST) Message-ID: <548DFF20.6090709@gmail.com> Date: Sun, 14 Dec 2014 21:20:32 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: internals@lists.php.net References: <2F9B99EF-538C-4225-95A4-943F57DADF69@ajf.me> In-Reply-To: <2F9B99EF-538C-4225-95A4-943F57DADF69@ajf.me> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [PATCH] Consistent type names in error messages From: rowan.collins@gmail.com (Rowan Collins) On 14/12/2014 18:35, Andrea Faulds wrote: > Good evening, > > Unfortunately, zend_parse_parameters and userland type hint error messages use outdated type names, and don’t even do so consistently. For example: > > $ php -r 'fread(0, 0);' > PHP Warning: fread() expects parameter 1 to be resource, integer given in Command line code on line 1 > > $ php -r 'fread(fopen("data:text/plain,test", "r"), fopen("data:text/plain,test", "r"));' > PHP Warning: fread() expects parameter 2 to be long, resource given in Command line code on line 1 > > $ php -r 'function foo(foobar $x) {} foo(1.0);' > PHP Catchable fatal error: Argument 1 passed to foo() must be an instance of foobar, double given, called in Command line code on line 1 and defined in Command line code on line 1 > > Specifically, zend_parse_parameters will always “expect” a “long”, yet when the expected type isn’t an integer and an integer is passed, it says “integer given”. Alongside this, both userland type hint errors and zend_parse_parameters errors refer to “double” and not “float”. > > I want to change the type names to be consistent, because I think our current inconsistency is confusing. Integers are sometimes ints or integers, but other times longs. Floats are sometimes floats, but other times doubles. If scalar type hints are ever added, then jettisoning the old aliases means we don’t have to add extra reserved words. > > I’ve made a patch which makes zend_parse_parameters and userland type hints consistently show “integer” and “float” rather than “long” and “double”: https://github.com/php/php-src/pull/955 > > I also wrote a GNU sed script which I used to update the tests: https://gist.github.com/TazeTSchnitzel/c0d780466def9f226318 > > Alongside error messages, there are some other places that could be changed. Obviously the return value of gettype() shouldn’t be changed, but I think that we should, for example, make is_long() an alias of is_int() and not the other way around. > > Thoughts? I had a go at this a few months ago, but haven't updated my patch based on what's changed in the engine since, so it probably wouldn't merge cleanly: https://github.com/php/php-src/pull/769 An additional case which it looks like you haven't covered is "Object of class %s could not be converted to double" in zend_operators.c and zend_object_handlers.c: https://github.com/IMSoP/php-src/commit/8dd601ac39a4241c9f119fd2d3e0e46474980a53 Other than the awkward BC implications in gettype(), I see no reason that the user should ever see the types labelled as "long" or "double" in their output. However, note that zend_get_type_by_const does get used in a handful of non-error contexts, such as the ReflectionClass output shown in ext/reflection/tests/bug29986.phpt [https://github.com/TazeTSchnitzel/php-src/commit/c0ee87297298b4ff9b8d68a01f8bbb99f94d9a10#diff-241] I had a grep around and couldn't see any that were likely to cause any real concern, though. Regards, -- Rowan Collins [IMSoP]