Bug #66739 [Opn]: strange behavior

From: Date: Wed, 19 Feb 2014 07:36:03 +0000
Subject: Bug #66739 [Opn]: strange behavior
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184356@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66739&edit=1

 ID:                 66739
 User updated by:    temenb at gmail dot com
 Reported by:        temenb at gmail dot com
 Summary:            strange behavior
 Status:             Open
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   ubuntu
 PHP Version:        5.4Git-2014-02-18 (Git)
 Block user comment: N
 Private report:     N

 New Comment:

Yes. It's true. not obvious. But php allows to call function this way


Previous Comments:
------------------------------------------------------------------------
[2014-02-19 02:53:53] coolwust at gmail dot com

B::b1();//b1 is object method

$b->b2();//b2 is static method

I think the syntax you calling the method is not correct

------------------------------------------------------------------------
[2014-02-18 22:45:16] temenb at gmail dot com

Description:
------------
static::foo() in the method A::a1() in some cases calls method B::foo()

It is not late static bindings,  B doesn't extend A

Test script:
---------------
<?php

class A
{
    public function a1()
    {             
        static::foo();
    }

    static public function a2()
    {       
        static::foo();
    }
    
    static public function foo()
    {
        echo 'A';
    }
}

class B
{
    public function b1()
    {
        A::a1();
        A::a2();
    }
    
    static public function b2()
    {
        A::a1();
        A::a2();
    }
    
    static public function foo()
    {    
        echo 'B';    
    }
}

B::b1();//A
B::b2();//A

$b = new B;
$b->b1();//B
$b->b2();//A



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



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


Thread (7 messages)

« previous php.bugs (#184356) next »