|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35252 __get not called if parameter exists
Submitted: 2005-11-17 04:55 UTC Modified: 2005-11-17 08:24 UTC
From: php at seven dot net dot nz Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5CVS-2005-11-17 (CVS) OS: Win XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: php at seven dot net dot nz
New email:
PHP Version: OS:


 [2005-11-17 04:55 UTC] php at seven dot net dot nz
When overloading a class, the __get magic function is not called if the parameter in question has been set on the object. I'm not sure if this is by design, but it seems to defeat the purpose of it somewhat.

Reproduce code:
class Cat {

	public function __get ($variable) {

		if (method_exists ($this, "get_$variable"))
			return $this->{"get_$variable"} ();
		elseif (isset ($this->$variable))
			return $this->$variable;
			throw new Exception ("$variable not found");


	public function get_noise () {
		return "Meow!";


$test = new Cat;
print $test->noise."\n";
$test->noise = "Woof!";
print $test->noise."\n";
print $test->get_noise ()."\n";
print $test->__get ("noise")."\n";

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-17 08:24 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

This is how it should work. __get() and __set() only work on non-set properties.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Mar 22 23:04:45 2023 UTC