php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43554 Calling a non static function staticaly causes scope importation
Submitted: 2007-12-10 16:18 UTC Modified: 2007-12-11 14:14 UTC
From: crashrox at gmail dot com Assigned: colder (profile)
Status: Wont fix Package: Class/Object related
PHP Version: 5.2.5 OS: Tested on Solaris & Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: crashrox at gmail dot com
New email:
PHP Version: OS:

 

 [2007-12-10 16:18 UTC] 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
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-10 18:42 UTC] 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-11 14:14 UTC] colder@php.net
The Class1 object scope is imported when calling Class2::dosomething() even it it's invalid.
A strict error is issued in such cases though.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 18:01:30 2024 UTC