#45159 [WFx]: __callStatic() called only in static methods

2008-06-04 Thread reto at buxaprojects dot com
 ID:   45159
 User updated by:  reto at buxaprojects dot com
 Reported By:  reto at buxaprojects dot com
 Status:   Wont fix
 Bug Type: Class/Object related
 Operating System: Fedora
 PHP Version:  6CVS-2008-06-03 (snap)
 New Comment:

ok, i see... what about the following fallback alternative for a call
like A::foo()

1. if method foo() in class A exists, call it, if not -> 2
2. if method __callstatic() implemented, call it, if not -> 3
3. if method __call implemented, call it, if not -> 4
4. fatal error

and there you have compatibility for php < 5.3.

For me A::foo() looks like a static call. Or do you really think it
always must follow the context? In my opinion, when calling a method in
the same style from different contexts, it isn't __always__ good that
they aren't treated the same...


Previous Comments:


[2008-06-03 23:41:29] [EMAIL PROTECTED]

You're misunderstanding the meaning of static::foo();

it doesn't mean "call foo statically" but rather "use runtime
information to get the class currently called", and do a static(or not)
call to the method of that class.

It's similar to
$name = get_called_class(); $name::foo();

For more information:
php.net/language.oop5.late-static-bindings



[2008-06-03 13:42:09] reto at buxaprojects dot com

I see your problem that "it would probably break things". But when i'm
calling a static method with static::coolMethod() i would expect that
this is __always__ a static call, why using the object context when it
can't be used in the static methods either?

In your example i would expect an Error that the foo() method of class
A can't be called statically.



[2008-06-03 13:15:27] [EMAIL PROTECTED]

Actually, in this particular case, it's completely expected.

Class A {
  public function foo() {

  }
}

class B extends A {
  public function bar() {
parent::foo(); // normal call
static::foo(); // normal call as well
A::foo(); // same here...
  }
}

$b = new B; $b->bar();

Now, for BC purposes, it would probably break things if those call
suddenly stop calling __call in case A::foo() wasn't defined, which how
it currently works in PHP 5.



[2008-06-03 13:10:08] [EMAIL PROTECTED]

This is somewhat expected, a call to foo::bar() from a non-static
context will be a non-static call, unless the function is explicitly
defined as static. 

However, some of this(especially the part about calling a "static
method" from/to an invalid context) is scheduled for cleanup.



[2008-06-03 11:59:19] reto at buxaprojects dot com

Description:

__call() instead of __callStatic() is called, when we call a static
method from a non-static method.

Reproduce code:
---
abstract class One
{
public function __call($m, $p)
{
echo '__call(' . $m . ') called' . "\n";
}
public static function __callStatic($m, $p)
{
echo '__callStatic(' . $m . ') called' . "\n";
}
}
class Two extends One
{
public function __construct()
{
$this->normalMethod();
self::staticMethod();
}

private function normalMethod()
{
echo 'normalMethod() called' . "\n";
parent::a();
self::b();
static::c();
One::d();
Two::e();
}

private static function staticMethod()
{
echo 'staticMethod() called' . "\n";
parent::a();
self::b();
static::c();
One::d();
Two::e();
}
}
$two = new Two();

Expected result:

normalMethod() called
__call(a) called
__callStatic(b) called
__callStatic(c) called
__callStatic(d) called
__callStatic(e) called
staticMethod() called
__callStatic(a) called
__callStatic(b) called
__callStatic(c) called
__callStatic(d) called
__callStatic(e) called


Actual result:
--
normalMethod() called
__call(a) called
__call(b) called
__call(c) called
__call(d) called
__call(e) called
staticMethod() called
__callStatic(a) called
__callStatic(b) called
__callStatic(c) called
__callStatic(d) called
__callStatic(e) called






-- 
Edit this bug report at http://bugs.php.net/?id=45159&edit=1



#45159 [WFx]: __callStatic() called only in static methods

2008-06-03 Thread colder
 ID:   45159
 Updated by:   [EMAIL PROTECTED]
 Reported By:  reto at buxaprojects dot com
 Status:   Wont fix
 Bug Type: Class/Object related
 Operating System: Fedora
 PHP Version:  6CVS-2008-06-03 (snap)
 New Comment:

You're misunderstanding the meaning of static::foo();

it doesn't mean "call foo statically" but rather "use runtime
information to get the class currently called", and do a static(or not)
call to the method of that class.

It's similar to
$name = get_called_class(); $name::foo();

For more information:
php.net/language.oop5.late-static-bindings


Previous Comments:


[2008-06-03 13:42:09] reto at buxaprojects dot com

I see your problem that "it would probably break things". But when i'm
calling a static method with static::coolMethod() i would expect that
this is __always__ a static call, why using the object context when it
can't be used in the static methods either?

In your example i would expect an Error that the foo() method of class
A can't be called statically.



[2008-06-03 13:15:27] [EMAIL PROTECTED]

Actually, in this particular case, it's completely expected.

Class A {
  public function foo() {

  }
}

class B extends A {
  public function bar() {
parent::foo(); // normal call
static::foo(); // normal call as well
A::foo(); // same here...
  }
}

$b = new B; $b->bar();

Now, for BC purposes, it would probably break things if those call
suddenly stop calling __call in case A::foo() wasn't defined, which how
it currently works in PHP 5.



[2008-06-03 13:10:08] [EMAIL PROTECTED]

This is somewhat expected, a call to foo::bar() from a non-static
context will be a non-static call, unless the function is explicitly
defined as static. 

However, some of this(especially the part about calling a "static
method" from/to an invalid context) is scheduled for cleanup.



[2008-06-03 11:59:19] reto at buxaprojects dot com

Description:

__call() instead of __callStatic() is called, when we call a static
method from a non-static method.

Reproduce code:
---
abstract class One
{
public function __call($m, $p)
{
echo '__call(' . $m . ') called' . "\n";
}
public static function __callStatic($m, $p)
{
echo '__callStatic(' . $m . ') called' . "\n";
}
}
class Two extends One
{
public function __construct()
{
$this->normalMethod();
self::staticMethod();
}

private function normalMethod()
{
echo 'normalMethod() called' . "\n";
parent::a();
self::b();
static::c();
One::d();
Two::e();
}

private static function staticMethod()
{
echo 'staticMethod() called' . "\n";
parent::a();
self::b();
static::c();
One::d();
Two::e();
}
}
$two = new Two();

Expected result:

normalMethod() called
__call(a) called
__callStatic(b) called
__callStatic(c) called
__callStatic(d) called
__callStatic(e) called
staticMethod() called
__callStatic(a) called
__callStatic(b) called
__callStatic(c) called
__callStatic(d) called
__callStatic(e) called


Actual result:
--
normalMethod() called
__call(a) called
__call(b) called
__call(c) called
__call(d) called
__call(e) called
staticMethod() called
__callStatic(a) called
__callStatic(b) called
__callStatic(c) called
__callStatic(d) called
__callStatic(e) called






-- 
Edit this bug report at http://bugs.php.net/?id=45159&edit=1



#45159 [WFx]: __callStatic() called only in static methods

2008-06-03 Thread reto at buxaprojects dot com
 ID:   45159
 User updated by:  reto at buxaprojects dot com
 Reported By:  reto at buxaprojects dot com
 Status:   Wont fix
 Bug Type: Class/Object related
 Operating System: Fedora
 PHP Version:  6CVS-2008-06-03 (snap)
 New Comment:

I see your problem that "it would probably break things". But when i'm
calling a static method with static::coolMethod() i would expect that
this is __always__ a static call, why using the object context when it
can't be used in the static methods either?

In your example i would expect an Error that the foo() method of class
A can't be called statically.


Previous Comments:


[2008-06-03 13:15:27] [EMAIL PROTECTED]

Actually, in this particular case, it's completely expected.

Class A {
  public function foo() {

  }
}

class B extends A {
  public function bar() {
parent::foo(); // normal call
static::foo(); // normal call as well
A::foo(); // same here...
  }
}

$b = new B; $b->bar();

Now, for BC purposes, it would probably break things if those call
suddenly stop calling __call in case A::foo() wasn't defined, which how
it currently works in PHP 5.



[2008-06-03 13:10:08] [EMAIL PROTECTED]

This is somewhat expected, a call to foo::bar() from a non-static
context will be a non-static call, unless the function is explicitly
defined as static. 

However, some of this(especially the part about calling a "static
method" from/to an invalid context) is scheduled for cleanup.



[2008-06-03 11:59:19] reto at buxaprojects dot com

Description:

__call() instead of __callStatic() is called, when we call a static
method from a non-static method.

Reproduce code:
---
abstract class One
{
public function __call($m, $p)
{
echo '__call(' . $m . ') called' . "\n";
}
public static function __callStatic($m, $p)
{
echo '__callStatic(' . $m . ') called' . "\n";
}
}
class Two extends One
{
public function __construct()
{
$this->normalMethod();
self::staticMethod();
}

private function normalMethod()
{
echo 'normalMethod() called' . "\n";
parent::a();
self::b();
static::c();
One::d();
Two::e();
}

private static function staticMethod()
{
echo 'staticMethod() called' . "\n";
parent::a();
self::b();
static::c();
One::d();
Two::e();
}
}
$two = new Two();

Expected result:

normalMethod() called
__call(a) called
__callStatic(b) called
__callStatic(c) called
__callStatic(d) called
__callStatic(e) called
staticMethod() called
__callStatic(a) called
__callStatic(b) called
__callStatic(c) called
__callStatic(d) called
__callStatic(e) called


Actual result:
--
normalMethod() called
__call(a) called
__call(b) called
__call(c) called
__call(d) called
__call(e) called
staticMethod() called
__callStatic(a) called
__callStatic(b) called
__callStatic(c) called
__callStatic(d) called
__callStatic(e) called






-- 
Edit this bug report at http://bugs.php.net/?id=45159&edit=1