Redirecting this to the list as this message was sent privately probably by accident :)
---------- Forwarded message ----------
From: Mathieu Rochette [email protected] Date: 2016-04-23 12:44 GMT-04:00
Subject: Re: [PHP-DEV][RFC] Callable Types To: Marcio Almada [email protected]
Hello everyone,
We just completed the draft for the "Callable Types" RFC. This RFC has been recently mentioned during other type related threads on this mailing list, so it feels to be the right time to put the proposal in context:
The proposal is at https://wiki.php.net/rfc/callable-types
It looks very nice overall :) and would be, imho, a great addition to PHP
I have a few comments, first about the optional arguments, the example in the rfc says :
// That means that foo() could call $cb and pass anything as a first argument and if it would be something that is not an instance of A the call would fail.
I don't get why foo would be declared as
function foo(callable() $cb) { }
instead of
function foo(callable($any) $cb) { }
if foo intends to call $cb with an argument.
what about optional arguments, eg:
class Foo
{
private $logger;
public __construct(Logger $logger = null) {$this->logger = $logger;} public doSomething(callable(int $done, int $remaining, Logger = null) $progressCb) {
// ...
for($i = 0; $i < $n; $i++) {
// ...
$progressCb($i, $n - $i, $this->logger); }
}
}
should that be supported ?
and last one, will instanceof supports this new syntax?
thank you
The W.I.P patch is available for testing through http://3v4l.org under the RFC tab.
We count with your detailed feedback and insights. Let's have a nice, respectful and
constructive conversation about the RFC and work on possible improvements!
Thanks
Nikita Nefedov
Márcio Almada
--
Mathieu Rochette
hi!
From: Mathieu Rochette [email protected]
Quoted text · 25 lines
Date: 2016-04-23 12:44 GMT-04:00
Subject: Re: [PHP-DEV][RFC] Callable TypesHello everyone,
We just completed the draft for the "Callable Types" RFC. This RFC has been recently mentioned during other type related threads on this mailing list, so it feels to be the right time to put the proposal in context:
The proposal is at https://wiki.php.net/rfc/callable-types
It looks very nice overall :) and would be, imho, a great addition to PHP
I have a few comments, first about the optional arguments, the example in the rfc says :
// That means that foo() could call $cb and pass anything as a first argument and if it would be something that is not an instance of A the call would fail.
I don't get why foo would be declared asfunction foo(callable() $cb) { }
instead of
function foo(callable($any) $cb) { }
if foo intends to call $cb with an argument.
what about optional arguments, eg:
class Foo
{
private $logger;
public __construct(Logger $logger = null) {$this->logger = $logger;} public doSomething(callable(int $done, int $remaining, Logger = null) $progressCb) {
// ...
for($i = 0; $i < $n; $i++) {
// ...
$progressCb($i, $n - $i, $this->logger); }
}
}should that be supported ?
Currently you can nullify or skip the Logger argument upon implementation of the callable. Rendering your example:
https://3v4l.org/qb5QR/rfc#tabs
Admittedly, the expectation for default values to work seems legit and we are currently discussing whether to support default values on callable types signatures or not (inclined to do not support). But honestly I haven't seen a legit use case when we already have the ability to satisfy the callback with a smaller type. Perhaps you may have one use case where a default value would be indispensable?
and last one, will instanceof supports this new syntax?
Yes, please expect to see this on the next minor version of the RFC :)
Quoted text · 9 lines
thank you
The W.I.P patch is available for testing through http://3v4l.org under the RFC tab.
We count with your detailed feedback and insights. Let's have a nice, respectful and
constructive conversation about the RFC and work on possible improvements!Thanks
Nikita Nefedov
Márcio Almada--
Mathieu Rochette
Cheers.
Quoted text · 31 lines
hi!
From: Mathieu Rochette [email protected]
Date: 2016-04-23 12:44 GMT-04:00
Subject: Re: [PHP-DEV][RFC] Callable TypesHello everyone,
We just completed the draft for the "Callable Types" RFC. This RFC has been recently mentioned during other type related threads on this mailing list, so it feels to be the right time to put the proposal in context:
The proposal is at https://wiki.php.net/rfc/callable-types
It looks very nice overall :) and would be, imho, a great addition to PHP
I have a few comments, first about the optional arguments, the example in the rfc says :
// That means that foo() could call $cb and pass anything as a first argument and if it would be something that is not an instance of A the call would fail.
I don't get why foo would be declared asfunction foo(callable() $cb) { }
instead of
function foo(callable($any) $cb) { }
if foo intends to call $cb with an argument.
what about optional arguments, eg:
class Foo
{
private $logger;
public __construct(Logger $logger = null) {$this->logger = $logger;} public doSomething(callable(int $done, int $remaining, Logger = null) $progressCb) {
// ...
for($i = 0; $i < $n; $i++) {
// ...
$progressCb($i, $n - $i, $this->logger); }
}
}should that be supported ?
Currently you can nullify or skip the Logger argument upon implementation of the callable. Rendering your example:
https://3v4l.org/qb5QR/rfc#tabs
Admittedly, the expectation for default values to work seems legit and we are currently discussing whether to support default values on callable types signatures or not (inclined to do not support). But honestly I haven't seen a legit use case when we already have the ability to satisfy the callback with a smaller type. Perhaps you may have one use case where a default value would be indispensable? I wouldn't say it's indispensable. it's just that in the previous example, the class Foo cannot say that the #rd argument of the callable is either a Logger or null.
that means that giving function(int $done, int $remaining){var_dump($remaining);} works but function(int $done, int $remaining, Logger $logger){$logger->debug($remaining);} does not even though it is compatible with the callable signature. and afaikt, I cannot make a signature without a default null value or one of the rfc about union types or nullable types
and last one, will instanceof supports this new syntax?
Yes, please expect to see this on the next minor version of the RFC :) great !
I've seen someone mentioning variadics so I made a few small tests, I think those two should work (they currently don't):
https://3v4l.org/eZgR9/rfc#rfc-callable_typehint https://3v4l.org/N7i0u/rfc#rfc-callable_typehint
and this one should not:
https://3v4l.org/fcRlT/rfc#rfc-callable_typehint
Quoted text · 10 lines
thank you
The W.I.P patch is available for testing through http://3v4l.org under the RFC tab.
We count with your detailed feedback and insights. Let's have a nice, respectful and
constructive conversation about the RFC and work on possible improvements!Thanks
Nikita Nefedov
Márcio Almada--
Mathieu RochetteCheers.
--
Mathieu Rochette