ID:               33856
 User updated by:  sr at brightlight dot ch
 Reported By:      sr at brightlight dot ch
 Status:           Bogus
 Bug Type:         Class/Object related
 Operating System: *
 PHP Version:      5.*
 New Comment:

Well, maybe it is not intended that way anymore, but as long 
as calling a function that way does not result in an error-
message it should be done correctly. A function opens a new 
scope and within that scope, $this should not be visible (as 
any other variable from the calling scope).
It is clear to me that this problem does not appear for pure 
static functions, but I happen to have some hybrid 
functions, that's why I discovered this problem at all.
But a question besides this: if calling via :: is only 
possible with static functions in future - is there still a 
way for developing hybrid functions that can be called 
either via -> or :: or is the only possible solution to have 
two different functions for the same?


Previous Comments:
------------------------------------------------------------------------

[2005-07-25 23:50:51] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Mark the function as static. It is only possible to call non static
methods as static methods for BC reasons.

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

[2005-07-25 23:46:58] sr at brightlight dot ch

Description:
------------
If a method is called via object::method(); from within a 
class method, then inside of the object::method(); the $this 
from the calling class method is visible.
This makes it almost impossible to tell if a method was 
invoked via -> or ::

Reproduce code:
---------------
<?php
        $test   = new testclass();
        $test->test();

        class testclass {
                function test() {
                        otherclass::staticFunction();
                        normalFunction();
                }
        }
        
        class otherclass {
                function staticFunction() {
                        echo "staticFunction: ".(isset($this) ? "set and of 
class:
".get_class($this)."\n" : "not set\n");
                }
        }

        function normalFunction() {
                echo "normalFunction: ".(isset($this) ? "set and of class:
".get_class($this)."\n" : "not set\n");
        }
?>

Expected result:
----------------
staticFunction: not set
normalFunction: not set

Actual result:
--------------
staticFunction: set and of class: testclass
normalFunction: not set


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


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

Reply via email to