Hi
As quickly mentioned in the '$arr = array('Hello', 'world'); $arr();'
thread[1], we are hitting the need for a callable typehint.
See attached patch+phpt; Any objections to include it in 5.4?
-Hannes
Hi!
See attached patch+phpt; Any objections to include it in 5.4?
Yes, same objections as for other static typing.
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Hi!
See attached patch+phpt; Any objections to include it in 5.4?
Yes, same objections as for other static typing.
That was totally not the purpose of this, and I don't quite understand
how you made the connection.
Like I mentioned in the other thread (which I probably should had
repeated here), a lot of libs/frameworks are using the 'Closure'
typehint for callbacks.
The problem with that is a function name as a string and
array("classname", "functionname") are considered is_callable()
.
To get through the intentions of the Closure hint, I would have to
wrap the actual callback in a closure - which doesn't make any sense.
-Hannes
Hi!
Like I mentioned in the other thread (which I probably should had
repeated here), a lot of libs/frameworks are using the 'Closure'
typehint for callbacks.
Well, they are wrong (unless they mean to use only closures and not
callbacks). But that's no reason to do wrong thing in the language too.
The problem with that is a function name as a string and
array("classname", "functionname") are consideredis_callable()
.
To get through the intentions of the Closure hint, I would have to
wrap the actual callback in a closure - which doesn't make any sense.
"callable" is not actually even a type. If we make it a language
construct, then why 'authenticated DB connection', 'name of readable
file', 'valid stream URL', 'validated XML', 'string in UTF-8 no longer
than 255 characters' or 'balanced binary tree' is not a language
construct? I don't think we need to put every data check into the
language, especially that it actually makes it worse - you can
gracefully handle user-space check, but not a strict typing error.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Like I mentioned in the other thread (which I probably should had
repeated here), a lot of libs/frameworks are using the 'Closure'
typehint for callbacks.Well, they are wrong (unless they mean to use only closures and not
callbacks). But that's no reason to do wrong thing in the language
too.The problem with that is a function name as a string and
array("classname", "functionname") are consideredis_callable()
. To
get through the intentions of the Closure hint, I would have to wrap
the actual callback in a closure - which doesn't make any sense."callable" is not actually even a type. If we make it a language
construct, then why 'authenticated DB connection', 'name of readable
file', 'valid stream URL', 'validated XML', 'string in UTF-8 no longer
than 255 characters' or 'balanced binary tree' is not a language
construct? I don't think we need to put every data check into the
language, especially that it actually makes it worse - you can
gracefully handle user-space check, but not a strict typing error.
The point, though, is that with such a typehint available, we can reduce
boilerplate code like the following:
public function addCallback($callback)
{
if (!is_callback($callback)) {
throw new InvalidArgumentException();
}
The typehint makes this simpler:
public function addCallback(callback $callback)
which allows us to rely on PHP's native error handling. I, for one,
would love to see this.
--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
How is this argument different than the one in favor of type hinting (or
whatever was what ended in trunk)?
On 7 Jun 2011 00:16, "Matthew Weier O'Phinney" weierophinney@php.net
wrote:
Like I mentioned in the other thread (which I probably should had
repeated here), a lot of libs/frameworks are using the 'Closure'
typehint for callbacks.Well, they are wrong (unless they mean to use only closures and not
callbacks). But that's no reason to do wrong thing in the language
too.The problem with that is a function name as a string and
array("classname", "functionname") are consideredis_callable()
. To
get through the intentions of the Closure hint, I would have to wrap
the actual callback in a closure - which doesn't make any sense."callable" is not actually even a type. If we make it a language
construct, then why 'authenticated DB connection', 'name of readable
file', 'valid stream URL', 'validated XML', 'string in UTF-8 no longer
than 255 characters' or 'balanced binary tree' is not a language
construct? I don't think we need to put every data check into the
language, especially that it actually makes it worse - you can
gracefully handle user-space check, but not a strict typing error.The point, though, is that with such a typehint available, we can reduce
boilerplate code like the following:public function addCallback($callback)
{
if (!is_callback($callback)) {
throw new InvalidArgumentException();
}The typehint makes this simpler:
public function addCallback(callback $callback)
which allows us to rely on PHP's native error handling. I, for one,
would love to see this.--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
--0016e6de0029ddc06f04a5129914
Content-Type: text/plain; charset=ISO-8859-1How is this argument different than the one in favor of type hinting (or
whatever was what ended in trunk)?
I was simply voicing my support for Hannes' patch, and trying to clarify
my understanding of it for Stas.
If you're comparing it to the scalar typehinting patch, I think it's a
far cry from that -- this is about providing a unified typehint for
functionality represented over multiple constructs in PHP, in order to
reduce code in applications. If it offers no BC issues, and allows
developers to simplify code and remove boilerplate (which can easily
introduce new errors on each iteration), then why wouldn't it be a good
idea?
On 7 Jun 2011 00:16, "Matthew Weier O'Phinney" weierophinney@php.net
wrote:Like I mentioned in the other thread (which I probably should had
repeated here), a lot of libs/frameworks are using the 'Closure'
typehint for callbacks.Well, they are wrong (unless they mean to use only closures and not
callbacks). But that's no reason to do wrong thing in the language
too.The problem with that is a function name as a string and
array("classname", "functionname") are consideredis_callable()
. To
get through the intentions of the Closure hint, I would have to wrap
the actual callback in a closure - which doesn't make any sense."callable" is not actually even a type. If we make it a language
construct, then why 'authenticated DB connection', 'name of readable
file', 'valid stream URL', 'validated XML', 'string in UTF-8 no longer
than 255 characters' or 'balanced binary tree' is not a language
construct? I don't think we need to put every data check into the
language, especially that it actually makes it worse - you can
gracefully handle user-space check, but not a strict typing error.The point, though, is that with such a typehint available, we can reduce
boilerplate code like the following:public function addCallback($callback)
{
if (!is_callback($callback)) {
throw new InvalidArgumentException();
}The typehint makes this simpler:
public function addCallback(callback $callback)
which allows us to rely on PHP's native error handling. I, for one,
would love to see this.--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc--
--0016e6de0029ddc06f04a5129914--
--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
> The point, though, is that with such a typehint available, we can reduce
> boilerplate code like the following:
Sure. How about reducing boilterplate code like this:
if(is_readable($foo)) {
$var = file_get_contents($foo);
} else {
throw InvalidArgumentException();
}
Why won't we make language construct to do that too? I don't think these
things belong in the language syntax.
>
> public function addCallback($callback)
> {
> if (!is_callback($callback)) {
> throw new InvalidArgumentException();
> }
>
> The typehint makes this simpler:
>
> public function addCallback(callback $callback)
>
You understand that these two pieces of code are completely different -
for one, you can't catch failing strict type check upstream of
addCallback and recover.
> which allows us to rely on PHP's native error handling. I, for one,
> would love to see this.
I wouldn't love it a bit, frankly, as "rely on PHP's native error
handling" in this context means "bombing out in runtime without any idea
what went wrong". When you have exception, you could make it print what
happened and recover, if you want. When you have fatal error, you can't
do much at all.
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Hi Stas,
I wouldn't love it a bit, frankly, as "rely on PHP's native error handling"
in this context means "bombing out in runtime without any idea what went
wrong". When you have exception, you could make it print what happened and
recover, if you want. When you have fatal error, you can't do much at all.
The patch as you probably know throws a E_RECOVERABLE_ERROR, which in
my humble opinion doesn't quite fall under the end-of-world category
you seem to explain there :- )
I.E.
function bar($a, $b, $c, $d)
{ return true; }
set_error_handler("bar");
class Foo
{
public function test(Array $arr) {}
}
$foo = new Foo; $foo->test('invalid');
echo "Everything will be okay.. :p";
-Chris
Martin Scotta
On Mon, Jun 6, 2011 at 8:02 PM, Stas Malyshev smalyshev@sugarcrm.comwrote:
Hi!
The point, though, is that with such a typehint available, we can reduce
boilerplate code like the following:
Sure. How about reducing boilterplate code like this:
if(is_readable($foo)) {
$var = file_get_contents($foo);
} else {
throw InvalidArgumentException();
}
trol?
Why won't we make language construct to do that too? I don't think these
things belong in the language syntax.public function addCallback($callback) { if (!is_callback($callback)) { throw new InvalidArgumentException(); }
The typehint makes this simpler:
public function addCallback(callback $callback)
You understand that these two pieces of code are completely different - for
one, you can't catch failing strict type check upstream of addCallback and
recover.which allows us to rely on PHP's native error handling. I, for one,
would love to see this.
I wouldn't love it a bit, frankly, as "rely on PHP's native error handling"
in this context means "bombing out in runtime without any idea what went
wrong". When you have exception, you could make it print what happened and
recover, if you want. When you have fatal error, you can't do much at all.--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Sure. How about reducing boilterplate code like this:
if(is_readable($foo)) {
$var = file_get_contents($foo);
} else {
throw InvalidArgumentException();
}Why won't we make language construct to do that too? I don't think these
things belong in the language syntax.
The whole point is that callables are generally not constructed from
user input, they're hardcoded in the code somewhere, and so if a fatal
error occurs, the developer notices it, hopefully during development.
With is_readable, a file can be anywhere, anytime, readable or not, it
depends on the environment the code runs on, and not on the code
itself, so it's not deterministic and you should therefore be able to
easily handle this gracefully.
Cheers
--
Jordi Boggiano
@seldaek :: http://seld.be/
Sure. How about reducing boilterplate code like this:
if(is_readable($foo)) {
$var = file_get_contents($foo);
} else {
throw InvalidArgumentException();
}Why won't we make language construct to do that too? I don't think these
things belong in the language syntax.The whole point is that callables are generally not constructed from
user input, they're hardcoded in the code somewhere, and so if a fatal
error occurs, the developer notices it, hopefully during development.With is_readable, a file can be anywhere, anytime, readable or not, it
depends on the environment the code runs on, and not on the code
itself, so it's not deterministic and you should therefore be able to
easily handle this gracefully.
Precisely.
I'd love to see a "callable" type hint too. And a "scalar" one while we're at it ;)
David
The point, though, is that with such a typehint available, we can
reduce boilerplate code like the following:public function addCallback($callback) { if (!is_callback($callback)) { throw new InvalidArgumentException(); }
The typehint makes this simpler:
public function addCallback(callback $callback)
which allows us to rely on PHP's native error handling. I, for one,
would love to see this.
That's the same reason why I wanted scalar type hints....
cheers,
Derick
--
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
Hi,
Hi!
See attached patch+phpt; Any objections to include it in 5.4?
Yes, same objections as for other static typing.
Those objections do not apply here IMO.
IIRC, the main objections were that if we introduce strict hints for
scalar values, then we start rejecting stuff that would "just work"
via implicit conversions before. i.e. "2" vs 2.
In this case, if you don't provide a valid callback to a function
expecting a valid callback, there is no way it will "just work".
Just like with other type hints, if you write function foo(A $b) and
pass B which is not a subtype of A, there is no way foo() will "just
work", as there is no way it will be able to interpret the value, an
object of type B, as an object of type A.
+1 from me, this seems very useful.
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227--
--
Etienne Kneuss
http://www.colder.ch
See attached patch+phpt; Any objections to include it in 5.4?
Hannes,
How about putting up an RFC for it? Even a brief RFC would be better than none.
Chris
--
Email: christopher.jones@oracle.com
Tel: +1 650 506 8630
Blog: http://blogs.oracle.com/opal/
On Mon, Jun 6, 2011 at 22:49, Christopher Jones
christopher.jones@oracle.com wrote:
See attached patch+phpt; Any objections to include it in 5.4?
Hannes,
How about putting up an RFC for it? Even a brief RFC would be better than
none.
https://wiki.php.net/rfc/callable
To avoid another flamewar..
Am I now supposed to create a new thread with [RFC] in the subject,
wait for minimum 2 weeks, and then create a poll somewhere on the wiki
and create new thread with [VOTE] in subject, and wait for another
2weeks and then if accepted by 50%+1 php.net developer, and 60% of the
community votes, then I can commit?
Thats the current rules of the game?
-Hannes
On Mon, Jun 6, 2011 at 22:49, Christopher Jones
christopher.jones@oracle.com wrote:See attached patch+phpt; Any objections to include it in 5.4?
Hannes,
How about putting up an RFC for it? Even a brief RFC would be better than
none.https://wiki.php.net/rfc/callable
To avoid another flamewar..
Am I now supposed to create a new thread with [RFC] in the subject,
wait for minimum 2 weeks, and then create a poll somewhere on the wiki
and create new thread with [VOTE] in subject, and wait for another
2weeks and then if accepted by 50%+1 php.net developer, and 60% of the
community votes, then I can commit?
Thats the current rules of the game?
I always thought it was publish and be damned.
--
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea
On Mon, Jun 6, 2011 at 22:49, Christopher Jones
christopher.jones@oracle.com wrote:See attached patch+phpt; Any objections to include it in 5.4?
Hannes,
How about putting up an RFC for it? Even a brief RFC would be better than
none.https://wiki.php.net/rfc/callable
To avoid another flamewar..
Am I now supposed to create a new thread with [RFC] in the subject,
wait for minimum 2 weeks, and then create a poll somewhere on the wiki
and create new thread with [VOTE] in subject, and wait for another
2weeks and then if accepted by 50%+1 php.net developer, and 60% of the
community votes, then I can commit?
Thats the current rules of the game?I always thought it was publish and be damned.
;)
That RFC process thread just became to much to pay attention to, so
I'm unsure what the status of it is.
-Hannes
On Mon, Jun 6, 2011 at 22:49, Christopher Jones
christopher.jones@oracle.com wrote:See attached patch+phpt; Any objections to include it in 5.4?
Hannes,
How about putting up an RFC for it? Even a brief RFC would be better than
none.
I've edited the "Problems" section to also point out that "Closure" is
considered an implementation detail which may change in the future --
which could potentially require changing any code type-hinting on it.
--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
Hi!
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 patch introduces new zval type IS_CALLABLE but zval functions
weren't updated for it - IIRC at least dtor may end up being called on
IS_CALLABLE value produced in the parser.
Note also that this pseudo-type is called "callback" in all of our
documentation, which means we have now documentation that says:
bool array_walk ( array &$array , callback $funcname [, mixed $userdata ] )
and type check that says "callable".
Also, it is not clear what would happen if this type check is made
against method which is not accessible (e.g. private out of scope).
Would it say that the argument is invalid (which would be really
confusing since it'd say something like "callable expected, array given"
which it technically correct but doesn't explain why this array is not
callable) or would allow it? If not, then zend_is_callable error
information should be used and displayed.
And the tests need to cover these cases, along with __call and
__callStatic.
For me personally it makes zero sense that having just removed strict
typing we are introducing it back through back door, but if everybody
likes it so be it.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Hi!
Note also that this pseudo-type is called "callback" in all of our documentation, which means we have now documentation that says:
bool array_walk ( array &$array , callback $funcname [, mixed $userdata ] )
and type check that says "callable".
Oh, good point. It should be "callback" then, too, maybe? Or the documentation should be adjusted (which might be a good idea, as "$funcname" doesn't reflect the realities anymore).
David
callback is callable, the opposite could not be true.
a string --or a closure-- is callable, but the string is not a callback
IMHO callable fits better.
Martin Scotta
On Tue, Jun 7, 2011 at 4:28 PM, David Zülke david.zuelke@bitextender.comwrote:
Hi!
Note also that this pseudo-type is called "callback" in all of our
documentation, which means we have now documentation that says:bool array_walk ( array &$array , callback $funcname [, mixed $userdata ]
)and type check that says "callable".
Oh, good point. It should be "callback" then, too, maybe? Or the
documentation should be adjusted (which might be a good idea, as "$funcname"
doesn't reflect the realities anymore).David
Hi!
callback is callable, the opposite could not be true.
a string --or a closure-- is callable, but the string is not a callback
According to our docs, which were out there for years, it is. One of the
main and widespread complaints about PHP is the lack of any system in
naming, design and documentation, it is sad to see how many people want
to make it worse instead of making it better.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Hi!
callback is callable, the opposite could not be true.
a string --or a closure-- is callable, but the string is not a callbackAccording to our docs, which were out there for years, it is. One of the main and widespread complaints about PHP is the lack of any system in naming, design and documentation, it is sad to see how many people want to make it worse instead of making it better
+1. I'm thinking it should be "callback", or the docs should be adjusted. "callable" arguably does make more sense, but either way, it needs to be consistent, that's what matters most.
David
To be honest: everybody knows what you mean when you say callback.
Callable sounds more like the name of an interface.
Hi!
callback is callable, the opposite could not be true.
a string --or a closure-- is callable, but the string is not a callbackAccording to our docs, which were out there for years, it is. One of the main and widespread complaints about PHP is the lack of any system in naming, design and documentation, it is sad to see how many people want to make it worse instead of making it better
+1. I'm thinking it should be "callback", or the docs should be adjusted. "callable" arguably does make more sense, but either way, it needs to be consistent, that's what matters most.
David
Hi!
callback is callable, the opposite could not be true. a string
--or a closure-- is callable, but the string is not a callbackAccording to our docs, which were out there for years, it is. One of
the main and widespread complaints about PHP is the lack of any system
in naming, design and documentation, it is sad to see how many people
want to make it worse instead of making it better+1. I'm thinking it should be "callback", or the docs should be
adjusted. "callable" arguably does make more sense, but either way, it
needs to be consistent, that's what matters most.
Agreed, here. "callback" is the usage throughout the documentation to
refer to anything that passes is_callable()
.
--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
+1 for "callable", it is really more consistent.
On Tue, Jun 7, 2011 at 3:44 PM, Matthew Weier O'Phinney <
weierophinney@php.net> wrote:
Hi!
callback is callable, the opposite could not be true. a string
--or a closure-- is callable, but the string is not a callbackAccording to our docs, which were out there for years, it is. One of
the main and widespread complaints about PHP is the lack of any system
in naming, design and documentation, it is sad to see how many people
want to make it worse instead of making it better+1. I'm thinking it should be "callback", or the docs should be
adjusted. "callable" arguably does make more sense, but either way, it
needs to be consistent, that's what matters most.Agreed, here. "callback" is the usage throughout the documentation to
refer to anything that passesis_callable()
.--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
--0016e68ee3e4bc4b0e04a525bac6
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable+1 for "callable", it is really more consistent.
I was actually agreeing With David and Stas that "callback" was more
consistent, and casting my vote for that.
On Tue, Jun 7, 2011 at 3:44 PM, Matthew Weier O'Phinney <
weierophinney@php.net> wrote:callback is callable, the opposite could not be true. a string
--or a closure-- is callable, but the string is not a callbackAccording to our docs, which were out there for years, it is. One of
the main and widespread complaints about PHP is the lack of any system
in naming, design and documentation, it is sad to see how many people
want to make it worse instead of making it better+1. I'm thinking it should be "callback", or the docs should be
adjusted. "callable" arguably does make more sense, but either way, it
needs to be consistent, that's what matters most.Agreed, here. "callback" is the usage throughout the documentation to
refer to anything that passesis_callable()
.
--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
On Tue, Jun 7, 2011 at 4:41 PM, Matthew Weier O'Phinney <
weierophinney@php.net> wrote:
--0016e68ee3e4bc4b0e04a525bac6
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable+1 for "callable", it is really more consistent.
I was actually agreeing With David and Stas that "callback" was more
consistent, and casting my vote for that.
Oh. But then, shouldn't is_callable be deprecated for a more consistently
named is_callback?
Regards,
David
On Tue, Jun 7, 2011 at 4:41 PM, Matthew Weier O'Phinney <
weierophinney@php.net> wrote:+1 for "callable", it is really more consistent.
I was actually agreeing With David and Stas that "callback" was more
consistent, and casting my vote for that.Oh. But then, shouldn't is_callable be deprecated for a more consistently
named is_callback?
No, because is_callable()
also performs visibility checks.
Which of course begs the question... should the type hint do the same?
David
2011/6/8 David Zülke david.zuelke@bitextender.com:
On Tue, Jun 7, 2011 at 4:41 PM, Matthew Weier O'Phinney <
weierophinney@php.net> wrote:+1 for "callable", it is really more consistent.
I was actually agreeing With David and Stas that "callback" was more
consistent, and casting my vote for that.Oh. But then, shouldn't is_callable be deprecated for a more consistently
named is_callback?No, because
is_callable()
also performs visibility checks.Which of course begs the question... should the type hint do the same?
David
+1 to "callback" (and have mercy on docs/translation people, it's too
much work to search/replace for such a minor difference :))
And yes, two similar terms (callback/callable) will make situation worse.
Plus to Johanness question: will it add runtime performance overhead
on code like this:
function(callback $callback = 'non_existent_function') {}
--
Regards,
Shein Alexey
We have the situation in the docs that parameters declared as arrays
do not follow the typehinting rules, but parameters as class names do.
Re-using the callback from the docs could get confusing when
extensions start to typehint on it, but not the core..
I think there is a subtle difference between a callback, and a callable.
In javascript for example, callback is something that is executed on
certain events "onsuccess" is the typical example.
There is nothing that says the callable parameter gets executed as a
part of an event, and I think the default usecase would be to execute
it right away (f.e. filtering data).
I think I would prefer callable, but I could live with either.
-Hannes
On Tue, Jun 7, 2011 at 23:41, Matthew Weier O'Phinney
weierophinney@php.net wrote:
--0016e68ee3e4bc4b0e04a525bac6
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable+1 for "callable", it is really more consistent.
I was actually agreeing With David and Stas that "callback" was more
consistent, and casting my vote for that.On Tue, Jun 7, 2011 at 3:44 PM, Matthew Weier O'Phinney <
weierophinney@php.net> wrote:callback is callable, the opposite could not be true. a string
--or a closure-- is callable, but the string is not a callbackAccording to our docs, which were out there for years, it is. One of
the main and widespread complaints about PHP is the lack of any system
in naming, design and documentation, it is sad to see how many people
want to make it worse instead of making it better+1. I'm thinking it should be "callback", or the docs should be
adjusted. "callable" arguably does make more sense, but either way, it
needs to be consistent, that's what matters most.Agreed, here. "callback" is the usage throughout the documentation to
refer to anything that passesis_callable()
.--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
2011/6/8 Hannes Magnusson hannes.magnusson@gmail.com:
We have the situation in the docs that parameters declared as arrays
do not follow the typehinting rules, but parameters as class names do.
Re-using the callback from the docs could get confusing when
extensions start to typehint on it, but not the core..I think there is a subtle difference between a callback, and a callable.
In javascript for example, callback is something that is executed on
certain events "onsuccess" is the typical example.
There is nothing that says the callable parameter gets executed as a
part of an event, and I think the default usecase would be to execute
it right away (f.e. filtering data).I think I would prefer callable, but I could live with either.
Wikipedia defines callback as "a reference to executable code, or a
piece of executable code, that is passed as an argument to other
code". So there's no "event" meaning put by default, it's just very
often seen callback's usage in javascript.
I just like "callback" term more :)
--
Regards,
Shein Alexey
2011/6/8 Hannes Magnusson hannes.magnusson@gmail.com:
We have the situation in the docs that parameters declared as arrays
do not follow the typehinting rules, but parameters as class names do.
Re-using the callback from the docs could get confusing when
extensions start to typehint on it, but not the core..I think there is a subtle difference between a callback, and a callable.
In javascript for example, callback is something that is executed on
certain events "onsuccess" is the typical example.
There is nothing that says the callable parameter gets executed as a
part of an event, and I think the default usecase would be to execute
it right away (f.e. filtering data).I think I would prefer callable, but I could live with either.
Wikipedia defines callback as "a reference to executable code, or a
piece of executable code, that is passed as an argument to other
code". So there's no "event" meaning put by default, it's just very
often seen callback's usage in javascript.
I just like "callback" term more :)
An interesting issue here.
Closures, classes with an __invoke method and strings containing
existing function names all pass is_callable()
and can be called using
().
But, array('class', 'method') also passes is_callable, but isn't a callback.
outputs ...
object is callable
Invoked : Wed, 08 Jun 2011 11:24:09 +0100
object is callable
Closure : Wed, 08 Jun 2011 11:24:09 +0100
string is callable
Wed, 08 Jun 2011 11:24:09 +0100
array is callable
Handling Array via call_user_func
Func array : Wed, 08 Jun 2011 11:24:09 +0100
So, callable and callbacks are 2 different things.
Callable
1 - closures.
2 - classes with an __invoke method.
3 - strings to an existing function.
4 - array('class', 'method')
Callbacks
Only 1, 2 and 3 from the above list.
If you try to use $funcarray(), you get the following fatal error ...
Fatal error: Function name must be a string
--
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea
2011/6/8 Hannes Magnusson hannes.magnusson@gmail.com:
We have the situation in the docs that parameters declared as arrays
do not follow the typehinting rules, but parameters as class names do.
Re-using the callback from the docs could get confusing when
extensions start to typehint on it, but not the core..I think there is a subtle difference between a callback, and a callable.
In javascript for example, callback is something that is executed on
certain events "onsuccess" is the typical example.
There is nothing that says the callable parameter gets executed as a
part of an event, and I think the default usecase would be to execute
it right away (f.e. filtering data).I think I would prefer callable, but I could live with either.
Wikipedia defines callback as "a reference to executable code, or a
piece of executable code, that is passed as an argument to other
code". So there's no "event" meaning put by default, it's just very
often seen callback's usage in javascript.
I just like "callback" term more :)An interesting issue here.
Closures, classes with an __invoke method and strings containing
existing function names all passis_callable()
and can be called using
().But, array('class', 'method') also passes is_callable, but isn't a callback.
It is after Felipes recent commit introducing $array();
-Hannes
If you try to use $funcarray(), you get the following fatal error ...
Fatal error: Function name must be a string
This is fixed. See thread
From: Felipe Pena felipensp@gmail.com
To: internals internals@lists.php.net
Subject: [PHP-DEV] $arr = array('Hello', 'world'); $arr();
Date: Sun, 5 Jun 2011 12:52:45 -0300 (06/ 5/11 05:52:45 PM)
johannes
2011/6/8 Johannes Schlüter johannes@schlueters.de:
If you try to use $funcarray(), you get the following fatal error ...
Fatal error: Function name must be a string
This is fixed. See thread
From: Felipe Pena felipensp@gmail.com
To: internals internals@lists.php.net
Subject: [PHP-DEV] $arr = array('Hello', 'world'); $arr();
Date: Sun, 5 Jun 2011 12:52:45 -0300 (06/ 5/11 05:52:45 PM)johannes
Thank you.
--
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea
Martin Scotta
2011/6/8 Hannes Magnusson hannes.magnusson@gmail.com:
We have the situation in the docs that parameters declared as arrays
do not follow the typehinting rules, but parameters as class names do.
Re-using the callback from the docs could get confusing when
extensions start to typehint on it, but not the core..I think there is a subtle difference between a callback, and a callable.
In javascript for example, callback is something that is executed on
certain events "onsuccess" is the typical example.
There is nothing that says the callable parameter gets executed as a
part of an event, and I think the default usecase would be to execute
it right away (f.e. filtering data).I think I would prefer callable, but I could live with either.
Wikipedia defines callback as "a reference to executable code, or a
piece of executable code, that is passed as an argument to other
code". So there's no "event" meaning put by default, it's just very
often seen callback's usage in javascript.
I just like "callback" term more :)
so 'strpos' is not a reference nor a piece of executable code, it's just the
name of a function, which is callable, although we can argue if the function
name could be seen as a reference to the code
--
Regards,
Shein Alexey
For me personally it makes zero sense that having just removed strict typing
we are introducing it back through back door, but if everybody likes it so
be it.
It's strict typing to have a type-hint that can be matched by 4
different constructs (string function names, arrays, closures,
invokable classes)? Basically anything that would succeed in
call_user_func would be allowed to pass...? There's no "dynamic
typing" that I'm aware of that this would prevent. Either it's
callable, or it's not. No casting or silent type conversion is going
to change that.
So it's not making typing stricter at all. All it does is allow you
to say "I want this parameter to be able to be directly called".
What form of call you give it doesn't matter one bit. So in a
sense, it's like having a String type-hint that casts if it can, but
throws an error if it can't (Ex: an object without __toString). This
will allow if there's a way to call it, and throw an error if not.
I'm all for this addition. +1
Hi!
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 patch introduces new zval type IS_CALLABLE but zval functions weren't
updated for it - IIRC at least dtor may end up being called on IS_CALLABLE
value produced in the parser.Note also that this pseudo-type is called "callback" in all of our
documentation, which means we have now documentation that says:bool array_walk ( array &$array , callback $funcname [, mixed $userdata ] )
and type check that says "callable".
Also, it is not clear what would happen if this type check is made against
method which is not accessible (e.g. private out of scope). Would it say
that the argument is invalid (which would be really confusing since it'd say
something like "callable expected, array given" which it technically correct
but doesn't explain why this array is not callable) or would allow it? If
not, then zend_is_callable error information should be used and displayed.
And the tests need to cover these cases, along with __call and __callStatic.For me personally it makes zero sense that having just removed strict typing
we are introducing it back through back door, but if everybody likes it so
be it.Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
hi Stas,
I have to say that we should apply our upcoming voting rule here as well.
If we don't, pls count -1 from here anyway.
Cheers,
Hi!
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 patch introduces new zval type IS_CALLABLE but zval functions weren't
updated for it - IIRC at least dtor may end up being called on IS_CALLABLE
value produced in the parser.Note also that this pseudo-type is called "callback" in all of our
documentation, which means we have now documentation that says:bool array_walk ( array &$array , callback $funcname [, mixed $userdata ] )
and type check that says "callable".
Also, it is not clear what would happen if this type check is made against
method which is not accessible (e.g. private out of scope). Would it say
that the argument is invalid (which would be really confusing since it'd say
something like "callable expected, array given" which it technically correct
but doesn't explain why this array is not callable) or would allow it? If
not, then zend_is_callable error information should be used and displayed.
And the tests need to cover these cases, along with __call and __callStatic.For me personally it makes zero sense that having just removed strict typing
we are introducing it back through back door, but if everybody likes it so
be it.Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227--
--
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Hi!
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")
What about default values? Will
function foo(callback $cb = 'strpos') { }
be valid?
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"?
What about ARGINFO? Will internal functions be able to define this type
via ARGINFO? How will this be reported in php --rf function
?
johannes
2011/6/8 Johannes Schlüter johannes@schlueters.de:
Hi!
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 inphp --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
2011/6/8 Johannes Schlüter johannes@schlueters.de:
Hi!
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.
Which means that
class callable { }
function f(callable $c) { }
f(new callable);
will be allowed by the parser but have a "strange" result? (This isn't
the case w/ array type hints as array is a parser token and can't be
used as class name (from userland at least))
If this feature is accepted we should have a good behavior there. I'm
not sure whether the right solution is to disallow naming classes
"callable" (or "callback" or whatever the name will be in the end)
Funny thing: Google Codesearch gives me one application defining an
class Callable. In that specific case the above thing would work:
http://google.com/codesearch/p?hl=en#vA7-IQSCKhE/trunk/php/framework/project/App/util/Callable.php&q=lang:php%20%22class%20callable%22&sa=N&cd=9&ct=rc
Sidenote: Looking for "class callback" gives me more false positives,
but also a few places where that classname is being used:
http://google.com/codesearch/p?hl=en#lYWaFFstwm4/tests/cases/libs/model/models.php&q=lang:php%20%22class%20callback%22&sa=N&cd=11&ct=rc
http://google.com/codesearch/p?hl=en#PbKZfG2CZcc/trunk/phpQuery/phpQuery/Callback.php&q=lang:php%20%22class%20callback%22&sa=N&cd=12&ct=rc&l=29
http://google.com/codesearch/p?hl=en#f6tUYQTbHns/trunk/framework/activerecord/lib/CallBack.php&q=lang:php%20%22class%20callback%22&sa=N&cd=21&ct=rc
...
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.
Ok. I assume NULL
as default value would be allowed, though. This would
be consistent for the language and allow such things:
function foo(callback $cb = NULL) {
if (!$cb) {
$cb = function() { /* .. default implementation */
}
....
}
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 :)
Good point. While I'd see that as defect, independently from scalar and
other type hints ;-)
What about ARGINFO? Will internal functions be able to define this type
via ARGINFO? How will this be reported inphp --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
That is fine.
Having the behavior cleared I wonder how useful it is in practical
terms. A class type hint guarantees me I can do a specific call to
methods defined in the class/interface. The proposed type hint tells me
I can call it in some way. It won't ensure that the signature is
compatible with what I expect.
function foo(callable $cb) {
$cb();
}
foo("strpos"); // This one in fact is illegal but won't be prevented
But maybe this doesn't matter as type hints purely serve documentation
(as E_RECOVERABLE are useless unless we make them Exceptions ...) while
even for documentation purpose more information is needed.
johannes
2011/6/8 Johannes Schlüter johannes@schlueters.de:
2011/6/8 Johannes Schlüter johannes@schlueters.de:
Hi!
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.
Which means that
class callable { }
No. 'callable' is a parser token.
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.Ok. I assume
NULL
as default value would be allowed, though. This would
be consistent for the language and allow such things:function foo(callback $cb = NULL) {
if (!$cb) {
$cb = function() { /* .. default implementation */
}
....
}
Etienne pointed out that default values for arrays can actually contain values..
I actually had no idea.
I suppose we then need to support default values for an array callable.
But yes, a callable can have the default value of null, following the
rules of class hinting.
-Hannes
A callable wouldn't be fully featured type.
Which means that
class callable { }No. 'callable' is a parser token.
Which has larger implications. This break code where people use callable
as constant, property, function or method name.
This seems to hit symfony and a few others.
http://google.com/codesearch?hl=en&lr=&q=lang%3Aphp+%22-%3Ecallable%
22&sbtn=Search
(yes breaking stuff can be fine, but we should at least be aware of
it ;-) )
Ok. I assume
NULL
as default value would be allowed, though. This would
be consistent for the language and allow such things:function foo(callback $cb = NULL) {
if (!$cb) {
$cb = function() { /* .. default implementation */
}
....
}Etienne pointed out that default values for arrays can actually contain values..
I actually had no idea.I suppose we then need to support default values for an array callable.
As I pointed out on IRC I'm not sure that's good, unless we want
closures as defaults, too. Which we probably won't like.
But yes, a callable can have the default value of null, following the
rules of class hinting.
Good.
johannes
Hi,
Having the behavior cleared I wonder how useful it is in practical
terms. A class type hint guarantees me I can do a specific call to
methods defined in the class/interface. The proposed type hint tells
me
I can call it in some way. It won't ensure that the signature is
compatible with what I expect.function foo(callable $cb) { $cb(); } foo("strpos"); // This one in fact is illegal but won't be
prevented
But maybe this doesn't matter as type hints purely serve documentation
(as E_RECOVERABLE are useless unless we make them Exceptions ...)
while
even for documentation purpose more information is needed.
Any comments to this? - I didn't see an answer before the votes were
opened.
johannes
Hi!
I can call it in some way. It won't ensure that the signature is
compatible with what I expect.
Well, it's like array type - you know it's an array but you can't know
if it contains certain element that you expect, for example. As I'm not
a big fan of strict typing in PHP anyway, I can't really defend this
thing, but this is nothing new - other type restrictions don't guarantee
you the code would work properly either, they only guarantee the type.
function foo(callable $cb) { $cb(); } foo("strpos"); // This one in fact is illegal but won't be
prevented
But maybe this doesn't matter as type hints purely serve documentation
(as E_RECOVERABLE are useless unless we make them Exceptions ...)
while
Indeed, E_RECOVERABLE is more or less useless - they are only marginally
better than E_ERROR
since error handler could be invoked on it. I do not
know why people think E_RECOVERABLE makes anything better.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
2011/7/10 Johannes Schlüter johannes@schlueters.de:
Hi,
Having the behavior cleared I wonder how useful it is in practical
terms. A class type hint guarantees me I can do a specific call to
methods defined in the class/interface. The proposed type hint tells
me
I can call it in some way. It won't ensure that the signature is
compatible with what I expect.function foo(callable $cb) {
$cb();
}
foo("strpos"); // This one in fact is illegal but won't be
preventedBut maybe this doesn't matter as type hints purely serve documentation
(as E_RECOVERABLE are useless unless we make them Exceptions ...)
while
even for documentation purpose more information is needed.Any comments to this? - I didn't see an answer before the votes were
opened.
Voting is open on this? I don't think I ever had the time to integrate
all the Q&A from this thread to the RFC.
If you typehint on Closure, you don't know if it takes 0 or 10
parameters either.
I don't think that is the point to know that either.
-Hannes
Hi!
Voting is open on this? I don't think I ever had the time to integrate
all the Q&A from this thread to the RFC.
If you think it's premature, we can postpone it. I've announced the
ballot on the list, but apparently not everybody is reading it ;)
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Hi!
Voting is open on this? I don't think I ever had the time to integrate
all the Q&A from this thread to the RFC.If you think it's premature, we can postpone it. I've announced the ballot
on the list, but apparently not everybody is reading it ;)
No no. Especially after seeing the currents votes ;)
Didn't notice your thread until just now.
I thought individual RFCs would be voted on first (into trunk), and
then there would be a vote on merging things from trunk.
This sort of heavy voting process is however new to me, will take some
time understanding and getting used to all the new rules around here.
-Hannes
Hi!
I thought individual RFCs would be voted on first (into trunk), and
then there would be a vote on merging things from trunk.
This sort of heavy voting process is however new to me, will take some
time understanding and getting used to all the new rules around here.
Well, this is kind of exceptional, because we had many things that were
discussed before we had RFC process and voting process decided on, and
we are in the release process. After we've cleaned our plate with this
vote, new ones would be individual and according to the new RFC.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
2011/7/11 Hannes Magnusson hannes.magnusson@gmail.com:
2011/7/10 Johannes Schlüter johannes@schlueters.de:
Hi,
Having the behavior cleared I wonder how useful it is in practical
terms. A class type hint guarantees me I can do a specific call to
methods defined in the class/interface. The proposed type hint tells
me
I can call it in some way. It won't ensure that the signature is
compatible with what I expect.function foo(callable $cb) {
$cb();
}
foo("strpos"); // This one in fact is illegal but won't be
preventedBut maybe this doesn't matter as type hints purely serve documentation
(as E_RECOVERABLE are useless unless we make them Exceptions ...)
while
even for documentation purpose more information is needed.Any comments to this? - I didn't see an answer before the votes were
opened.Voting is open on this? I don't think I ever had the time to integrate
all the Q&A from this thread to the RFC.
The related vote is in the "Voting for 5.4 features" vote [1], which
asks "do we want to include this feature in 5.4 release?" (and oddly,
a preferred choice of callback/callable/neither). Voting on the RFC
itself, the implementation details and such, will obviously be your
call. Whether it makes sense to say "yes we want this in 5.4" before a
more general vote on the RFC itself ("yes, we want this"), I'm not
sure.
[1] https://wiki.php.net/todo/php54/vote
If you typehint on Closure, you don't know if it takes 0 or 10
parameters either.
I don't think that is the point to know that either.-Hannes
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.
Unless I mis-read what you said, we already have default array values
for array type-hinting:
function foo(array $array = array('bar', 'baz')) {
var_dump($array);
}
foo();
foo(array());
Works perfectly for me on 5.3.6...
2011/6/8 Hannes Magnusson hannes.magnusson@gmail.com:
2011/6/8 Johannes Schlüter johannes@schlueters.de:
Hi!
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 inphp --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
Martin Scotta
On Wed, Jun 8, 2011 at 10:31 AM, Anthony Ferrara ircmaxell@gmail.comwrote:
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.Unless I mis-read what you said, we already have default array values
for array type-hinting:function foo(array $array = array('bar', 'baz')) {
var_dump($array);
}foo();
foo(array());
Works perfectly for me on 5.3.6...
it works since long time ago
2011/6/8 Hannes Magnusson hannes.magnusson@gmail.com:
2011/6/8 Johannes Schlüter johannes@schlueters.de:
Hi!
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 inphp --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
He means
function foo(callback derp = array('MyClass', 'ohai')) { ... }
David
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.Unless I mis-read what you said, we already have default array values
for array type-hinting:function foo(array $array = array('bar', 'baz')) {
var_dump($array);
}foo();
foo(array());
Works perfectly for me on 5.3.6...
2011/6/8 Hannes Magnusson hannes.magnusson@gmail.com:
2011/6/8 Johannes Schlüter johannes@schlueters.de:
Hi!
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 inphp --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
Hi!
Am I now supposed to create a new thread with [RFC] in the subject,
wait for minimum 2 weeks, and then create a poll somewhere on the wiki
and create new thread with [VOTE] in subject, and wait for another
2weeks and then if accepted by 50%+1 php.net developer, and 60% of the
community votes, then I can commit?
Thats the current rules of the game?
Not really, we never had 50%+1 rule and I really hope we never will. But
the rest is close to what is being currently proposed.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
On Tue, Jun 7, 2011 at 8:50 PM, Stas Malyshev smalyshev@sugarcrm.comwrote:
Hi!
Am I now supposed to create a new thread with [RFC] in the subject,
wait for minimum 2 weeks, and then create a poll somewhere on the wiki
and create new thread with [VOTE] in subject, and wait for another
2weeks and then if accepted by 50%+1 php.net developer, and 60% of the
community votes, then I can commit?
Thats the current rules of the game?Not really, we never had 50%+1 rule and I really hope we never will. But
the rest is close to what is being currently proposed.
50%+1 is the required majority for changes which doesn't affect the syntax
or the language in some important way(I agree that this RFC would need 2/3
of the votes as it introduces a new typehint), on the other hand we have no
precedence for the community votes.
sorry for resurrecting the thread, but I think that having a Callable
typehint would be nice, and I agree with Etienne that the generic arguments
against typehints doesn't really apply here.
--
Ferenc Kovács
@Tyr43l - http://tyrael.hu
<snip> sorry for resurrecting the thread, but I think that having a Callable typehint would be nice, and I agree with Etienne that the generic arguments against typehints doesn't really apply here.
We've had "callable" since 5.4.0.
--
Ferenc Kovács
@Tyr43l - http://tyrael.hu
2013.05.28. 8:48, "Peter Cowburn" petercowburn@gmail.com ezt írta:
<snip>sorry for resurrecting the thread, but I think that having a Callable
typehint would be nice, and I agree with Etienne that the generic
arguments
against typehints doesn't really apply here.We've had "callable" since 5.4.0.
--
Ferenc Kovács
@Tyr43l - http://tyrael.hu
I blame the morning.
:/
Hello,
On Mon, Jun 6, 2011 at 12:41 PM, Hannes Magnusson
hannes.magnusson@gmail.com wrote:
Hi
As quickly mentioned in the '$arr = array('Hello', 'world'); $arr();'
thread[1], we are hitting the need for a callable typehint.
This brings a clear and concise enhancement to PHP which I would
benefit from .I have been watching our API provide more and more
functions with callbacks as arguments and it would be nice to have a
specific type for those to clean up the is_callable error handling.
It is my opinion that comparing it to previous type hinting proposals
is like comparing apples and oranges. I think it falls in align
justification wise between Class Name and Array type hints.
I.E.
function test1(StdClass $p) ..
function test2(Closure $p) ... <== doesn't this seem more justified
then "Array" given the argument of previous type hinting proposals?
function test3(Array $arr)
+1 from me
-Chris
Hello,
On Mon, Jun 6, 2011 at 3:51 PM, Chris Stockton
chrisstocktonaz@gmail.com wrote:
Hello,
On Mon, Jun 6, 2011 at 12:41 PM, Hannes Magnusson
hannes.magnusson@gmail.com wrote:Hi
As quickly mentioned in the '$arr = array('Hello', 'world'); $arr();'
thread[1], we are hitting the need for a callable typehint.This brings a clear and concise enhancement to PHP which I would
benefit from .I have been watching our API provide more and more
functions with callbacks as arguments and it would be nice to have a
specific type for those to clean up the is_callable error handling.It is my opinion that comparing it to previous type hinting proposals
is like comparing apples and oranges. I think it falls in align
justification wise between Class Name and Array type hints.I.E.
function test1(StdClass $p) ..
function test2(Closure $p) ... <== doesn't this seem more justified
then "Array" given the argument of previous type hinting proposals?
function test3(Array $arr)+1 from me
-Chris
s/Closure/Callable/g
On Mon, Jun 6, 2011 at 9:41 PM, Hannes Magnusson <hannes.magnusson@gmail.com
wrote:
Hi
As quickly mentioned in the '$arr = array('Hello', 'world'); $arr();'
thread[1], we are hitting the need for a callable typehint.See attached patch+phpt; Any objections to include it in 5.4?
-Hannes
[1] http://php.markmail.org/message/gdas65h3im52sleg
--
+1 but please create an RFC for it, or we will argue this to death.
Tyrael
Dne 6.6.2011 21:41, Hannes Magnusson napsal(a):
Hi
As quickly mentioned in the '$arr = array('Hello', 'world'); $arr();'
thread[1], we are hitting the need for a callable typehint.See attached patch+phpt; Any objections to include it in 5.4?
-Hannes
I like the idea. However I think the type hint should be named
"callback" instead of "callable" because this name is used already in a
lot of documentations and also in PHP documentation
http://php.net/manual/en/language.pseudo-types.php#language.types.callback
Jaroslav Hanslik