Re: [PHP-DEV] RFC: alternative callback syntax

2012-09-20 Thread Ivan Enderlin @ Hoa

On 19/09/12 19:41, Steve Clay wrote:

On 9/19/12 9:26 AM, Ivan Enderlin @ Hoa wrote:

callable is already a reserved word (T_CALLABLE).


Oh, good. It's not listed here http://php.net/manual/en/tokens.php

Exactly. Who is responsible to update the documentation? Julien?

Best regards.

--
Ivan Enderlin
Developer of Hoa
http://hoa.42/ or http://hoa-project.net/

PhD. student at DISC/Femto-ST (Vesontio) and INRIA (Cassis)
http://disc.univ-fcomte.fr/ and http://www.inria.fr/

Member of HTML and WebApps Working Group of W3C
http://w3.org/


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RFC: alternative callback syntax

2012-09-20 Thread Pierre Joye
hi,

On Thu, Sep 20, 2012 at 10:09 AM, Ivan Enderlin @ Hoa
ivan.ender...@hoa-project.net wrote:
 On 19/09/12 19:41, Steve Clay wrote:

 On 9/19/12 9:26 AM, Ivan Enderlin @ Hoa wrote:

 callable is already a reserved word (T_CALLABLE).


 Oh, good. It's not listed here http://php.net/manual/en/tokens.php

 Exactly. Who is responsible to update the documentation? Julien?

Open a bug at bugs.php.net or http://edit.php.net/ or post on the
php-doc mailing list :)

Cheers,
-- 
Pierre

@pierrejoye

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RFC: alternative callback syntax

2012-09-20 Thread Ivan Enderlin @ Hoa


On 19/09/12 20:21, Steve Clay wrote:

On 9/19/12 2:01 PM, Andrew Faulds wrote:

Some other ideas:

$cb = (callable) $obj-bar;
Ah, but (callable) that won't work for global functions, since 
(callable) is a cast, and


(callable) is not usable as a cast (at least in 5.4.7):

$a = (callable)'str'; // Parse error: syntax error, unexpected 
'callable' (T_CALLABLE)


This could work, and it makes sense to me at least.



$cb = {mysql_real_escape_string};
$cb = {mysql_real_escape_string};

These notations are just horrible.

PHP has recently introduced ::class to resolve a classname (namespace 
Foo; A::class // Foo\A). The “::” was originally a resolution operator 
for calls, but now, it is also used for names (which sounds good for 
me). Here, you propose the new notation ::function, which can be 
understood as: “resolve this function or method as a callable”. We stay 
in a resolution context. It is consistent regarding to the evolution of 
this operator.


Another consistent notation is the cast: (callable) $obj-bar;.

However, having { } around with  is absolutely horrible. It is an awful 
blend between references and dynamic variables, it is not consistent and 
error-prone when reading.


Cheers :-).

--
Ivan Enderlin
Developer of Hoa
http://hoa.42/ or http://hoa-project.net/

PhD. student at DISC/Femto-ST (Vesontio) and INRIA (Cassis)
http://disc.univ-fcomte.fr/ and http://www.inria.fr/

Member of HTML and WebApps Working Group of W3C
http://w3.org/



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RFC: alternative callback syntax

2012-09-20 Thread Adam Harvey
On 20 September 2012 16:24, Ivan Enderlin @ Hoa
ivan.ender...@hoa-project.net wrote:

 On 9/19/12 2:01 PM, Andrew Faulds wrote:
 $cb = {mysql_real_escape_string};
 $cb = {mysql_real_escape_string};

 These notations are just horrible.

Agreed. They're very line noisey and non-obvious.

 PHP has recently introduced ::class to resolve a classname (namespace Foo;
 A::class // Foo\A). The “::” was originally a resolution operator for calls,
 but now, it is also used for names (which sounds good for me). Here, you
 propose the new notation ::function, which can be understood as: “resolve
 this function or method as a callable”. We stay in a resolution context. It
 is consistent regarding to the evolution of this operator.

I like ::callable, personally, since it suggests the resulting type,
but ::function would also be OK by me.

 Another consistent notation is the cast: (callable) $obj-bar;.

I think the analogy with ::class is stronger than the analogy with
type casting (since it's not a variable or literal), although I'm not
really too fussed either way.

In terms of the feature itself (since I haven't weighed in yet), I
think it's a reasonable piece of syntactic sugar, although I'd
definitely want to see a patch before voting. :)

Adam

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] RFC: alternative callback syntax

2012-09-20 Thread Pete Boere
Tentative +1 for the func_name::callable version.

callable seems more generic, and possibly more intuitive when scan reading
code that contains lots of 'function'.

class A {
static function init() {
$inst = new self;
var_export http://www.php.net/var_export($inst-bar::callable);
$inst-bar();
}
function bar() {
var_export http://www.php.net/var_export(B::baz::callable);
}}





-- 
Pete Boere
Web Developer


Re: [PHP-DEV] RFC: alternative callback syntax

2012-09-20 Thread Ivan Enderlin @ Hoa

On 20/09/12 10:17, Pierre Joye wrote:

hi,

On Thu, Sep 20, 2012 at 10:09 AM, Ivan Enderlin @ Hoa
ivan.ender...@hoa-project.net wrote:

On 19/09/12 19:41, Steve Clay wrote:

On 9/19/12 9:26 AM, Ivan Enderlin @ Hoa wrote:

callable is already a reserved word (T_CALLABLE).


Oh, good. It's not listed here http://php.net/manual/en/tokens.php

Exactly. Who is responsible to update the documentation? Julien?

Open a bug at bugs.php.net or http://edit.php.net/ or post on the
php-doc mailing list :)

Patch has been proposed through http://edit.php.net.

--
Ivan Enderlin
Developer of Hoa
http://hoa.42/ or http://hoa-project.net/

PhD. student at DISC/Femto-ST (Vesontio) and INRIA (Cassis)
http://disc.univ-fcomte.fr/ and http://www.inria.fr/

Member of HTML and WebApps Working Group of W3C
http://w3.org/


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RFC: alternative callback syntax

2012-09-19 Thread Sebastian Krebs
2012/9/19 Steve Clay st...@mrclay.org

 Hello,

 https://wiki.php.net/rfc/**alternative_callback_syntaxhttps://wiki.php.net/rfc/alternative_callback_syntaxis
  a proposal for a simple alternative syntax for creating function
 callbacks.

 The basics: Given a function/method call, replace the argument list with
 ::function. PHP would evaluate this as a callback for the
 function/method, fully resolving any class/function names according to the
 current namespace and any use statements.

 In my opinion this syntax would aid readability and benefit users via
 fewer typos and namespace errors, and via (hopefully) better IDE support.


 I welcome any feedback. I don't have adequate C skills to offer a patch at
 the moment, but I generally read everything I can get my hands on about how
 PHP features are implemented and am not afraid to jump in.

 Thanks for your time.

 P.S. I've kicked around this idea around for awhile, but Ralph Schindler's
 idea for using ::keyword provided a better path to BC, and more
 attractive/meaningful syntax.

 P.P.S. I'm unaware if it's customary to throttle the release of RFCs, so I
 apologize for hogging any attention away from those under discussion.

 Steve Clay


Hi,

Beside that I like the idea to get rid of defining callbacks as string (for
the same reason I like 'Classname::class' for classes) I don't like, that
functions will look like classes with a static property function then ...

Regards,
Sebastian



 --
 http://www.mrclay.org/

 --
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
github.com/KingCrunch


Re: [PHP-DEV] RFC: alternative callback syntax

2012-09-19 Thread Steve Clay

On 9/19/12 2:37 AM, Sebastian Krebs wrote:

2012/9/19 Steve Clay st...@mrclay.org mailto:st...@mrclay.org

https://wiki.php.net/rfc/__alternative_callback_syntax



reason I like 'Classname::class' for classes) I don't like, that functions will 
look like
classes with a static property function then ...


FWIW, here are the syntaxes I've considered:

func_name; // parser can't distinguish from constant

callablefor func_name; // adds reserved word, token

func_name::callable; // adds reserved word

func_name::function; // in RFC

Steve
--
http://www.mrclay.org/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RFC: alternative callback syntax

2012-09-19 Thread Ivan Enderlin @ Hoa


On 19/09/12 15:15, Steve Clay wrote:

On 9/19/12 2:37 AM, Sebastian Krebs wrote:

2012/9/19 Steve Clay st...@mrclay.org mailto:st...@mrclay.org

https://wiki.php.net/rfc/__alternative_callback_syntax


reason I like 'Classname::class' for classes) I don't like, that 
functions will look like

classes with a static property function then ...


FWIW, here are the syntaxes I've considered:

func_name; // parser can't distinguish from constant

callablefor func_name; // adds reserved word, token

func_name::callable; // adds reserved word

callable is already a reserved word (T_CALLABLE).



func_name::function; // in RFC

Steve


--
Ivan Enderlin
Developer of Hoa
http://hoa.42/ or http://hoa-project.net/

PhD. student at DISC/Femto-ST (Vesontio) and INRIA (Cassis)
http://disc.univ-fcomte.fr/ and http://www.inria.fr/

Member of HTML and WebApps Working Group of W3C
http://w3.org/


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RFC: alternative callback syntax

2012-09-19 Thread Levi Morrison
On Tue, Sep 18, 2012 at 8:48 PM, Steve Clay st...@mrclay.org wrote:

 Hello,

 https://wiki.php.net/rfc/alternative_callback_syntax is a proposal for a 
 simple alternative syntax for creating function callbacks.

 The basics: Given a function/method call, replace the argument list with 
 ::function. PHP would evaluate this as a callback for the function/method, 
 fully resolving any class/function names according to the current namespace 
 and any use statements.

 In my opinion this syntax would aid readability and benefit users via fewer 
 typos and namespace errors, and via (hopefully) better IDE support.


 I welcome any feedback. I don't have adequate C skills to offer a patch at 
 the moment, but I generally read everything I can get my hands on about how 
 PHP features are implemented and am not afraid to jump in.

 Thanks for your time.

 P.S. I've kicked around this idea around for awhile, but Ralph Schindler's 
 idea for using ::keyword provided a better path to BC, and more 
 attractive/meaningful syntax.

 P.P.S. I'm unaware if it's customary to throttle the release of RFCs, so I 
 apologize for hogging any attention away from those under discussion.

 Steve Clay
 --
 http://www.mrclay.org/

 --
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php


I do not like this proposal.  The syntax is ugly and not intuitive.
We need a different way to accomplish this.

Levi Morrison

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RFC: alternative callback syntax

2012-09-19 Thread Andrew Faulds

On 19/09/12 18:16, Levi Morrison wrote:

On Tue, Sep 18, 2012 at 8:48 PM, Steve Clay st...@mrclay.org wrote:

Hello,

https://wiki.php.net/rfc/alternative_callback_syntax is a proposal for a simple 
alternative syntax for creating function callbacks.

The basics: Given a function/method call, replace the argument list with 
::function. PHP would evaluate this as a callback for the function/method, 
fully resolving any class/function names according to the current namespace and any use 
statements.

In my opinion this syntax would aid readability and benefit users via fewer 
typos and namespace errors, and via (hopefully) better IDE support.


I welcome any feedback. I don't have adequate C skills to offer a patch at the 
moment, but I generally read everything I can get my hands on about how PHP 
features are implemented and am not afraid to jump in.

Thanks for your time.

P.S. I've kicked around this idea around for awhile, but Ralph Schindler's idea 
for using ::keyword provided a better path to BC, and more 
attractive/meaningful syntax.

P.P.S. I'm unaware if it's customary to throttle the release of RFCs, so I 
apologize for hogging any attention away from those under discussion.

Steve Clay
--
http://www.mrclay.org/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php


I do not like this proposal.  The syntax is ugly and not intuitive.
We need a different way to accomplish this.
I completely agree. How about function_name? Resembles C (function 
pointers!), and unless I'm getting confused, it isn't currently legal 
syntax for something else.


--
Andrew Faulds
http://ajf.me/


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RFC: alternative callback syntax

2012-09-19 Thread Steve Clay

On 9/19/12 9:26 AM, Ivan Enderlin @ Hoa wrote:

callable is already a reserved word (T_CALLABLE).


Oh, good. It's not listed here http://php.net/manual/en/tokens.php

Steve
--
http://www.mrclay.org/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RFC: alternative callback syntax

2012-09-19 Thread Steve Clay

On 9/19/12 1:19 PM, Andrew Faulds wrote:

I completely agree. How about function_name? Resembles C (function pointers!), 
and unless
I'm getting confused, it isn't currently legal syntax for something else.


$cb =  Foo::doSomething;
$cb =  foo_doSomething;
$cb =  $obj-doSomething;

The last looks like a reference to a property, though having verb method names would help 
distinguish. Not sure if the ambiguity would make this difficult to implement.


Some other ideas:

$cb = (callable) $obj-bar;
$cb = callable $obj-bar;
$cb = callable::$obj-bar;
$cb = $obj-bar::callable;

Steve
--
http://www.mrclay.org/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RFC: alternative callback syntax

2012-09-19 Thread Andrew Faulds

On 19/09/12 18:56, Steve Clay wrote:

On 9/19/12 1:19 PM, Andrew Faulds wrote:
I completely agree. How about function_name? Resembles C (function 
pointers!), and unless
I'm getting confused, it isn't currently legal syntax for something 
else.


$cb =  Foo::doSomething;
$cb =  foo_doSomething;
$cb =  $obj-doSomething;

The last looks like a reference to a property, though having verb 
method names would help distinguish. Not sure if the ambiguity would 
make this difficult to implement.

Oops, good point!


Some other ideas:

$cb = (callable) $obj-bar;
Ah, but (callable) that won't work for global functions, since 
(callable) is a cast, and if I try to do:


$cb= (callable) mysql_real_escape_string;

I'd actually try to access a constant named 'mysql_real_escape_string' 
(bad!!)

$cb = callable $obj-bar;
$cb = callable::$obj-bar;
$cb = $obj-bar::callable;

Here's two other possibilities from me:

$cb = {mysql_real_escape_string};
$cb = {mysql_real_escape_string};

Both are completely illegal just now, I think.


Steve



--
Andrew Faulds
http://ajf.me/


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RFC: alternative callback syntax

2012-09-19 Thread Steve Clay

On 9/19/12 2:01 PM, Andrew Faulds wrote:

Some other ideas:

$cb = (callable) $obj-bar;

Ah, but (callable) that won't work for global functions, since (callable) is a 
cast, and


(callable) is not usable as a cast (at least in 5.4.7):

$a = (callable)'str'; // Parse error: syntax error, unexpected 'callable' 
(T_CALLABLE)

This could work, and it makes sense to me at least.



 $cb = {mysql_real_escape_string};
 $cb = {mysql_real_escape_string};


I'll add these possibilities to the RFC soon.

Steve
--
http://www.mrclay.org/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] RFC: alternative callback syntax

2012-09-19 Thread Andrew Faulds

On 19/09/12 19:21, Steve Clay wrote:

On 9/19/12 2:01 PM, Andrew Faulds wrote:

Some other ideas:

$cb = (callable) $obj-bar;
Ah, but (callable) that won't work for global functions, since 
(callable) is a cast, and


(callable) is not usable as a cast (at least in 5.4.7):

$a = (callable)'str'; // Parse error: syntax error, unexpected 
'callable' (T_CALLABLE)


This could work, and it makes sense to me at least.
Yes, the problem is that it would add a special syntax case, where 
(cast)identifier, in this case, uses a function name, not an expression. 
This is bad.


--
Andrew Faulds
http://ajf.me/


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php