php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51888 overloaded __set is called from parent class
Submitted: 2010-05-22 17:17 UTC Modified: 2010-05-25 09:08 UTC
From: j dot jeising at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.3.2 OS: Mac OS X
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: j dot jeising at gmail dot com
New email:
PHP Version: OS:

 

 [2010-05-22 17:17 UTC] j dot jeising at gmail dot com
Description:
------------
If you overwrite __set in a child class, the parent implementation is called first 
and than triggers the child version.

I found another bug, which says that you should implement the __set method in the 
parent class, but it in this case both methods are called.

A similar bug is reported in #44807, but it's only about the recursion prevention.

Test script:
---------------
<?php
	class Foo {
		function __set($key, $value) {
			$this->{$key} = $value . ' (Foo)';
		}
	}
	
	class Bar extends Foo {
		function __set($key, $value) {
			$this->{$key} = $value . ' (Bar)';
		}
		
		function set() {
			parent::__set('foobar', 'Test');
		}
	}
	
	$bar = new Bar();
	$bar->set();
	echo $bar->foobar;
?>

Expected result:
----------------
Test (Foo)

Actual result:
--------------
Test (Foo) (Bar)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-25 09:08 UTC] mike@php.net
-Status: Open +Status: Bogus
 [2010-05-25 09:08 UTC] mike@php.net
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

YOU call parent::__set() which assigns an unkown property, which in turn calls the __set() of the child.

Jeeeeez
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 23 04:01:32 2024 UTC