Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class A
- {
- protected $a;
- public function __construct()
- {
- $this->a = array( new B, new B );
- }
- public function __toString()
- {
- return json_encode( $this->a );
- }
- }
- class B
- {
- protected $b = array( 'foo' => 'bar' );
- public function __toString()
- {
- return json_encode( $this->b );
- }
- }
- $a = new A();
- echo $a;
- [{},{}]
- [{"foo":"bar"},{"foo":"bar"}]
- class a
- {
- public function __set( $prop, $value )
- {
- echo __METHOD__, PHP_EOL;
- $this->$prop = $value;
- }
- public function __toString()
- {
- return json_encode( $this );
- }
- }
- $a = new a;
- $a->foo = 'bar';
- $a->foo = 'baz';
- echo $a;
- class a
- {
- public $foo;
- public function setFoo( $value )
- {
- $this->foo = $value;
- }
- public function __toString()
- {
- return json_encode( $this );
- }
- }
- $a = new a;
- $a->setFoo( 'bar' );
- echo $a;
- <?php
- class a implements IteratorAggregate
- {
- public $foo = 'bar';
- protected $bar = 'baz';
- public function getIterator()
- {
- echo __METHOD__;
- }
- }
- echo json_encode( new a );
- [{"b":{"foo":"bar"}},{"b":{"foo":"bar"}}]
- [{"foo":"bar"},{"foo":"bar"}]
- class B
- {
- protected $b = array( 'foo' => 'bar' );
- public function __get($name)
- {
- return json_encode( $this->$name );
- }
- }
- class A
- {
- protected $a;
- public function __construct()
- {
- $b1 = new B;
- $b2 = new B;
- $this->a = array( json_decode($b1->b), json_decode($b2->b) );
- }
- public function __toString()
- {
- return json_encode( $this->a );
- }
- }
- class A
- {
- protected $a;
- public function __construct()
- {
- $this->a = array( (string)new B, (string)new B );
- }
- public function __toString()
- {
- return json_encode( $this->a );
- }
- }
- $this->a = array( json_decode((string)new B), json_decode((string)new B) );
- $b1 = new B;
- $b2 = new B;
- $this->a = array( $b1->toArray(), $b2->toArray() );
Add Comment
Please, Sign In to add comment