[PHP-DEV] call_user_func performance and dynamic code

2011-05-22 Thread Drak
I'd like to ask a question about call_user_func/_array performance and
the use of runtime variables to call functions and methods from the
PHP internals perspective.

Many people have blogged about how:-

$callable = array($object, $bar);
call_user_func_array($callable, $args);

is considerably slower than

$object->$bar($args);

and there seem to be plenty benchmarks to back this up.

What is the official standpoint from the PHP developers and is there
are reason to use call_user_func/_array over using variables to
express the call when considering opcode caching?  What I mean for
example, is, when using $foo->$bar($args) at runtime, maybe this is
faster than call_user_func but maybe not if an opcode cache is
involved (e.g. maybe it cannot cache $foo).  I ask this because things
like __call() and __get() are also notoriously slow.

Also, would there be a reason for certain dynamic notations to be
slower than others (again with and without opcode caching incolved) -
a few examples below:

$foo();
$foo->$bar();
$array[0]->$array[1];
$foo::bar();
$array[0]::$array[1]();

PHP has evolved a lot over the years so it would be nice to know what
the intention, pros and cons of these methodologies are from an
official internals point of view and if anything has been changed to
over time to make these methodologies more efficient.

Regards,

Drak

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



Re: [PHP-DEV] Constructor object instance dereferentiation

2011-05-22 Thread Felipe Pena
Hi,

2011/5/22 Matthew Weier O'Phinney 

> One thing not on the RFC that I'm curious about: if the class defines
> __invoke(), would the following work?
>
>new MyClass()();
>
> That would be particularly useful for implementing helper systems, which
> are quite often one-off use cases.
>
>
No, such feature was not planned in the RFC, the patch doesn't change the
grammar to allow it.

-- 
Regards,
Felipe Pena


Re: [PHP-DEV] Constructor object instance dereferentiation

2011-05-22 Thread Matthew Weier O'Phinney
On 2011-05-22, Ferenc Kovacs  wrote:
> --bcaec52be62721150704a3d8f926
> Content-Type: text/plain; charset=UTF-8
>
> On Sun, May 22, 2011 at 6:18 AM, dukeofgaming  wrote:
> > I was wondering if object dereferentiation after constructor call is
> > something that has been discussed already. This is, being able to do
> > something like:
> >
> > new MyClass()-> setSomething();
> >
> > Instead of:
> >
> > $var = new MyClass();
> > $var-> setSomething();
>
> it was already discussion, Felipe created an RFC and a patch, the responses
> was all positive, so I think if nobody changed their mind, we could move
> this from Under Discussion to Accepted/Implemented
> as I said before, it would be in good pair with the already implemented
> array dereferencing (https://wiki.php.net/rfc/functionarraydereferencing)
>
> http://marc.info/?l=php-internals&m=129080024516125&w=2
> https://wiki.php.net/rfc/instance-method-call

One thing not on the RFC that I'm curious about: if the class defines
__invoke(), would the following work?

new MyClass()();

That would be particularly useful for implementing helper systems, which
are quite often one-off use cases.

-- 
Matthew Weier O'Phinney
Project Lead| matt...@zend.com
Zend Framework  | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

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



Re: [PHP-DEV] Constructor object instance dereferentiation

2011-05-22 Thread dukeofgaming
On Sun, May 22, 2011 at 3:16 AM, Ferenc Kovacs  wrote:
>
>
> hi.
>
> it was already discussion, Felipe created an RFC and a patch, the responses
> was all positive, so I think if nobody changed their mind, we could move
> this from Under Discussion to Accepted/Implemented
> as I said before, it would be in good pair with the already implemented
> array dereferencing (https://wiki.php.net/rfc/functionarraydereferencing)
>
> http://marc.info/?l=php-internals&m=129080024516125&w=2
> https://wiki.php.net/rfc/instance-method-call
>
> Tyrael
>

Hi,

Nice, it would indeed make sense to include it with array dereferencing.
This feature would enter in the PHP 5.4 release along with array
dereferencing, is this correct?.

Regards,

David


Re: [PHP-DEV] Constructor object instance dereferentiation

2011-05-22 Thread Ferenc Kovacs
On Sun, May 22, 2011 at 6:18 AM, dukeofgaming wrote:

> Hi,
>
> I was wondering if object dereferentiation after constructor call is
> something that has been discussed already. This is, being able to do
> something like:
>
> new MyClass()->setSomething();
>
> Instead of:
>
> $var = new MyClass();
> $var->setSomething();
>
> Regards,
>
> David Vega
>

hi.

it was already discussion, Felipe created an RFC and a patch, the responses
was all positive, so I think if nobody changed their mind, we could move
this from Under Discussion to Accepted/Implemented
as I said before, it would be in good pair with the already implemented
array dereferencing (https://wiki.php.net/rfc/functionarraydereferencing)

http://marc.info/?l=php-internals&m=129080024516125&w=2
https://wiki.php.net/rfc/instance-method-call

Tyrael