ID:               43554
 Updated by:       [EMAIL PROTECTED]
-Summary:          Calling a non static function staticaly causes local
                   assignment
 Reported By:      crashrox at gmail dot com
-Status:           Closed
+Status:           Wont fix
 Bug Type:         Class/Object related
 Operating System: Tested on Solaris & Windows
 PHP Version:      5.2.5
-Assigned To:      
+Assigned To:      colder
 New Comment:

The Class1 object scope is imported when calling Class2::dosomething()
even it it's invalid.
A strict error is issued in such cases though.


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

[2007-12-10 18:42:09] crashrox at gmail dot com

This is apparently documented in the manual. Took some time to find it
but seems to me it would still be a scope issue. Either way I'm wrong,
so this is closed.

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

[2007-12-10 16:18:22] crashrox at gmail dot com

Description:
------------
You have two classes (Class1 and Class2). Class1 calls a non static
Class2 function with a Class2 variable assignment, but without a return
value. The value set in Class2 is somehow assigned to Class1. If the
function was set to static or the class is instantiated the problem does
not occur. See code example below for better explanation...

Reproduce code:
---------------
// UNEXPECTED RESULTS
class Class1 {
        public function __construct() {
                Class2::dosomething();
        }
}

class Class2 {
        
        private $somevar;
        public  function dosomething() {
                $this->somevar = 'test';
        }
        
        
}

$x = new Class1();
print_r($x);


/*
// WORKS CORRECTLY
class Class1 {
        public function __construct() {
                $x = new Class2();
                $x->dosomething();
        }
}

class Class2 {

        private $somevar;
        public  function dosomething() {
                $this->somevar = 'test';
        }
        
        
}

$x = new Class1();
print_r($x);
*/

Expected result:
----------------
Class1 Object ( )

Actual result:
--------------
Class1 Object
(
    [somevar] => test
)


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


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

Reply via email to