Re: Callable type

From: Date: Wed, 08 Jun 2011 08:38:51 +0000
Subject: Re: Callable type
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
2011/6/8 Johannes Schlüter <[email protected]>:
> On Tue, 2011-06-07 at 12:12 -0700, Stas Malyshev wrote:
>> Hi!
>>
>> > https://wiki.php.net/rfc/callable
>>
>> It is good there's an RFC. However it seems to lack code examples. I
>> understand it may be obvious to the proposers how it looks like, but
>> it'd be nice to have the actual example there as it is done nearly
>> everywhere else.
>
> The RFC is missing information about what happens in codebases which
> already have a "callable" type declared. Will that be prevented or will
> they hit a runtime error? ("callable expected, callable type found")

You mean an interface/class with that name?
The error would be 'expected instanceof callable, string/array/closure recieved.

gettype("strpos") will still return a string, not callable.

A callable wouldn't be fully featured type.

> What about default values? Will
>    function foo(callback $cb = 'strpos') { }
> be valid?

No default values, other then NULL allowed.
Otherwise we would need to support array("classname", "methodname")
too, and then people would want default array values for array
typehinting etc etc etc.



> The information on reflection is limited. what shall
> Reflection::Parameter::getTypehint() return? Will that method allow to
> differ between a class type and this "magic"?

There is no such method anymore :)


>
> What about ARGINFO? Will internal functions be able to define this type
> via ARGINFO? How will this be reported in php --rf function?

I didn't include arginfo in the patch, but good point. It should
probably be included.
As Felipe pointed out, ext/reflection hasn't been updated.
It should return [ callable $foobar ], just like with any other typehint

-Hannes


Thread (63 messages)

« previous php.internals (#53196) next »