Re: Reviving scalar type hints

From: Date: Tue, 17 Feb 2015 09:27:45 +0000
Subject: Re: Reviving scalar type hints
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-82936@lists.php.net to get a copy of this message
On 02/17/2015 01:11 AM, Benjamin Eberlei wrote: > I think curl_setopt is a misleading example in the typehinting > discussion, because > this kind of API does not benefit from it. The third argument depends > on the second argument and requires a "generic" type in code: > > curl_setopt(resource $ch, int $option, mixed $data); > > It won't be possible to change this (or any similar API) with strict > type hints. > > The code to convert a boolean $data to integer in the VERIFYPEER case is > manually > implemented and therefore subject to the implementors design decisions. Sure, I realize this, but it is the bool->int coercion example that is always brought up. A static analysis type checker would have trouble catching this, but both PHP and Hack apply that coercion at runtime: case CURLOPT_SSL_VERIFYHOST: if(Z_BVAL_PP(zvalue) == 1) { The runtime could say, hey, I am in strict mode here and you are passing me an array of strings which I am coercing to a boolean. Not cool. -Rasmus

Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
« previous php.internals (#82936) next »