RE: [PHP-DEV] [PATCH] Late Static Binding

From: Date: Wed, 01 Mar 2006 12:59:01 +0000
Subject: RE: [PHP-DEV] [PATCH] Late Static Binding
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
I didn't look into the patch deep.
But I see one critical issue:

Patched PHP will modify zend_function->caller_scope at runtime.
This can break ZTS version and probaby opcode caches.
Storing runtime information in zend_function is bad decision.

Also the name "static" confusing me.
Because "self" behave more 'static' (and proper).

Thanks. Dmitry.

> -----Original Message-----
> From: Marcus Boerger [mailto:[email protected]] 
> Sent: Wednesday, March 01, 2006 3:03 PM
> To: Dmitry Stogov
> Cc: 'PHP-DEV'; 'Mike Lively'
> Subject: Re: [PHP-DEV] [PATCH] Late Static Binding
> 
> 
> Hello Dmitry,
> 
>   of course, what hinders you?
> See original mail from Mike: http://news.php.net/php.internals/21991
> 
> regards
> marcus
> 
> Wednesday, March 1, 2006, 12:51:51 PM, you wrote:
> 
> > Can I look into patch?
> 
> > Dmitry.
> 
> >> -----Original Message-----
> >> From: Marcus Boerger [mailto:[email protected]]
> >> Sent: Wednesday, March 01, 2006 1:01 PM
> >> To: PHP-DEV
> >> Cc: Andi Gutmans; Mike Lively
> >> Subject: Re: [PHP-DEV] [PATCH] Late Static Binding
> >> 
> >> 
> >> Hello internals,
> >> 
> >>    it looks like either nobody objects or nobody has
> >> interest. Either way i tested the patch and worked helped it 
> >> a bit and it looks good, doesn't affect anything else and 
> >> doesn't show a single problem in valgrind. So If noone 
> >> objects i will commit this next week.
> >> 
> >> regards
> >> marcus
> >> 
> >> special mail to andi :-)
> >> 
> >> 
> >> Thursday, February 23, 2006, 11:06:02 PM, you wrote:
> >> 
> >> > I have finished a patch that implements a working version of late
> >> > static binding.
> >> 
> >> > I used the notes from the Paris PDM as my guidelines for
> >> > implementation.
> >> > 
> >> (http://www.php.net/~derick/meeting-notes.html#late-static-bin
> > ding-using-this-without-or-perhaps-with-a-different-name)
> >> > As requested in the notes I reused 'static::'. I also wrote
> >> a few tests
> >> > not only to test the new functionality but also to make
> >> sure 'static' can't be inherited or extended.
> >> 
> >> > I also added a new function get_caller_class() which
> >> returns the name
> >> > of the class that static:: would represent.
> >> 
> >> > (borrowing from PDM notes)
> >> > In php5.* the following script outputs "A::static2":
> >> 
> >> > <?php
> >> >         class A {
> >> >                 static function staticA() {
> >> >                         self::static2();
> >> >                 }
> >> 
> >> >                 static function static2() {
> >> >                         echo "A::static2\n";
> >> >                 }
> >> >         }
> >> 
> >> >         class B extends A {
> >> >                 static function static2() {
> >> >                         echo "B::static2\n";
> >> >                 }
> >> >         }
> >> 
> >> >         B::staticA();
> >> ?>>
> >> 
> >> > This has somewhat recently been highlighted by different
> >> developers to
> >> > be somewhat problematic behavior in creating user 
> friendly APIs. If
> >> > you want to see a possible use for it you need look no 
> further than 
> >> > the example ZActiveRecord API that was used in their 
> webcast with 
> >> > php|arch.
> >> > 
> >> (http://blog.joshuaeichorn.com/archives/2006/01/09/zactivereco
> >> rd-cant-work/)
> >> > Currently the code laid out there is impossible short of
> >> some ugly use of
> >> > debug_backtrace() and file parsing :/. This patch of course
> >> would allow that kind of code too exist.
> >> 
> >> > In a small example based on the one I gave earlier you 
> could change
> >> > the code too the following and have it print "B::static2":
> >> 
> >> > <?php
> >> >         class A {
> >> >                 static function staticA() {
> >> >                         static::static2();
> >> >                 }
> >> 
> >> >                 static function static2() {
> >> >                         echo "A::static2\n";
> >> >                 }
> >> >         }
> >> 
> >> >         class B extends A {
> >> >                 static function static2() {
> >> >                         echo "B::static2\n";
> >> >                 }
> >> >         }
> >> 
> >> >         B::staticA();
> >> ?>>
> >> 
> >> > As far as current userland code impact, there is very
> >> little as far as
> >> > I can tell. No keywords have been added, just another use for an
> >> > existing one. No changes were made to self:: or parent:: so 
> >> the change
> >> > should be pretty transparent. The only thing that I see remotely
> >> > causing any issues would be the new function 
> >> (get_caller_class().) I
> >> > added that just to complete the set so to speak.
> >> 
> >> 
> >> --
> >> PHP Internals - PHP Runtime Development Mailing List
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >> 
> >> 
> >> 
> 
> 
> 
> 
> Best regards,
>  Marcus
> 
> 
> 


Thread (59 messages)

« previous php.internals (#22048) next »