There is a serious problem with both of these patches as they are now.

I understand the principal behind
<?

class A {
   static public function test() { echo get_called_class() }
}

class B extend A {
   static public function test2() { A::test(); }
}

B::test2()

?>

Returning 'A'. But I don't think that it is wise making this change without providing a way to still allow LSB to work further down an inheritance structure.

The whole purpose behind late static binding is to offer greater flexibility when dealing with inheritance of static functions. I understand that the aspect of the original patch returning 'B' for the code above is incorrect. However, consider the following scenario.

<?php

class A {
   static public function test() {
       echo get_called_class()."\n";
   }
}

class B {
   static public function test() {
       // Performing additional needed tasks.
       parent::test();
   }
}

?>

In class B it is impossible to perform additional work in ::test() and allow class A to still do it's work while still being able to identify the class that originated the set of calls. I don't think it can be denied that this is incredibly inflexible and is somewhat against the reason for introducing late static binding.

I think it is important that a solution is found to this problem, whether it is allowing parent:: to forward on the 'called class' or introducing a new keyword:: that will forward on the 'called class'.

Also, just as a somewhat obvious side note I think the ability to do what I have mentioned will be expected by the OO programmers (which is who lsb is for):
<?php

class A
{
       public function test()
       {
               echo get_class($this);
       }
}

class B extends A
{
       public function test()
       {
               // Performing additional needed tasks.
               parent::test();
       }
}

$b = new B();
$b->test();
?>

Returns 'B' with no problem


----- Original Message ----- From: "Dmitry Stogov" <[EMAIL PROTECTED]>
To: "'Etienne Kneuss'" <[EMAIL PROTECTED]>
Cc: <internals@lists.php.net>; "Stanislav Malyshev" <[EMAIL PROTECTED]>; "Andi Gutmans" <[EMAIL PROTECTED]>
Sent: Tuesday, September 18, 2007 5:59 AM
Subject: RE: [PHP-DEV] [patch] Late static bindings (LSB)


Hi Etienne,

At first thank you for catching the issue.

I deside not to delay review of your patch and found only one serious bug.
It doesn't handle nested calls (test lsb_017.phpt in my patch).

--TEST--
ZE2 nested calls
--FILE--
<?php
class A {
public static function test($x=null) {
if (!is_null($x)) {
echo "$x\n";
}
return get_caller_class();
}
}

class B extends A {
}
class C extends A {
}
class D extends A {
}

echo A::test(B::test(C::test(D::test())))."\n";
?>
==DONE==
--EXPECT--
D
C
B
A
==DONE==

Your patch outputs 4 D.

BTW I like other aspects of your patch.
I think your get_called_class() is better than my get_caller_class(). (I
changed this in my new patch).

I also made the same behavior that you maintained in private email. I didn't
removed the corresponding code yet but wrapped it with #ifdef ZEND_LSB2.
(tests lsb_018.phpt and test_019.phpt must be failed without it).

I also made several optimizations.

The latest version of my patch is attached.
I think if you fix the bug that I maintained before our patches will near
identical.
BTW may be your patch will be better, so please make a mixture of our
patches.
I assume they have exactly the same behavior, so we need the fastest one.

Thanks. Dmitry.

-----Original Message-----
From: Etienne Kneuss [mailto:[EMAIL PROTECTED]
Sent: Sunday, September 16, 2007 8:18 PM
To: Dmitry Stogov
Cc: internals@lists.php.net
Subject: Re: [PHP-DEV] [patch] Late static bindings (LSB)


Hello,

I made the update anyway as it looked like it wouldn't take much time.

Attached is a updated version of my patch, along with all the tests
related to it:
http://patches.colder.ch/Zend/late_static_bindings_take7.patch?markup

--
Etienne Kneuss
http://www.colder.ch

Men never do evil so completely and cheerfully as
when they do it from a religious conviction.
-- Pascal





--------------------------------------------------------------------------------


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


--------------------------------------------------------------------------------


No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.487 / Virus Database: 269.13.21/1010 - Release Date: 9/15/2007 7:54 PM

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

Reply via email to