Hello, please sign in or register
You are here: Home

PHP overload get and set problems

Regarding PHP5 OOP Overload methods e.g. __get, __set, __call, etc...

Defining the overload methods will fail any assignment of an undefied array.

<?php

class test
{
	public function __set( $nm, $val )
	{
		return ( $this->$nm = $val );
	}
	public function __get( $nm )
	{
		return $this->$nm;
	}
}

$c = new test();
$c->undefined_array[] = "two";
var_dump( $c->undefined_array );
// NULL

?>

Whilst if we remove the __get and __set methods this will work as it does with regular variable assignment

<?php

class test
{
}

$c = new test();
$c->undefined_array[] = "two";
var_dump( $c->undefined_array );
/**
 * array(1) {
 *  [0]=>
 *  string(3) "two"
 * }
 */
?>

Or if we merely define the variable first

<?php

class test
{
	public function __set( $nm, $val )
	{
		return ( $this->$nm = $val );
	}

	public function __get( $nm )
	{
		return $this->$nm;
	}
}


$c = new test();
$c->defined_array = array();
$c->defined_array[] = "one";
var_dump( $c->defined_array );
/**
 * array(1) {
 *  [0]=>
 *  string(3) "one"
 */
?>

Comments

PkORjqhDIEfkw
I thought finding this would be so arduous but it's a bereze!
Created 18/08/11
aeiZwulOW
DFviN1 rwofmsizcjfg
Created 19/08/11
lWPIOVYSOu
ko8RK9 , [url=http://wynupmrscsxj.com/]wynupmrscsxj[/url], [link=http://vauynjxcgmqd.com/]vauynjxcgmqd[/link], http://ubopxhluoffq.com/
Created 19/08/11
yaLvGcpdBDMUUkfLbqz
X6LHlf muvzuvkuoxyf
Created 25/08/11
XqzZyXkmQaLzJasvRaa
mb0yeC , [url=http://efoaqdlkkfok.com/]efoaqdlkkfok[/url], [link=http://glfmuiknhafm.com/]glfmuiknhafm[/link], http://jmirtrwqeuod.com/
Created 30/08/11
0921maoqiuyun
cheap nba jerseys, http://www.nbajerseys.net/ jordan shoes, http:/...
Created 21/09/15
guoyanying
But the replica watches sentry reebok shoes knew abercrombie and fitch uk his
Created 07/10/15
1015maoqiuyun
coach outlet online, http://www.coachoutletonline-store.us.com/
Created 15/10/15
mmdr
yeezy boost 350 yeezy boost 350 yeezy boost 350
Created 25/03/16
wq123
This hilfiger outlet time swarovski jewelry something really timberland outlet strange, ...
Created 30/06/16
ninestab123
ninest123 One canada goose pas cher gucci outlet thing
Created 21/07/16
chenyingying
nike tn 2016 coach outlet online cheap nhl j...
Created 16/11/16
michael kors factory outlet
adidas nmd pandora bracelet
Created 16/05/17
Title*
Comment

Prove you are not a robot

To prove you are not a robot, please type in the six character code you see in the picture below
Security confirmation codeI can't see this!
Contact
Name*
Email never shown*
Home Page

Author

Andrew Dodson
Since:Feb 2007

Comment | flag

Categories

Bookmark and Share