File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / tests / classes / __set__get_001.phpt
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 23:48:06 2012 UTC (12 years, 6 months ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_29p0, v5_4_29, v5_4_20p0, v5_4_20, v5_4_17p0, v5_4_17, v5_3_10, HEAD
php

    1: --TEST--
    2: ZE2 __set() and __get()
    3: --SKIPIF--
    4: <?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
    5: --FILE--
    6: <?php
    7: class setter {
    8: 	public $n;
    9: 	public $x = array('a' => 1, 'b' => 2, 'c' => 3);
   10: 
   11: 	function __get($nm) {
   12: 		echo "Getting [$nm]\n";
   13: 
   14: 		if (isset($this->x[$nm])) {
   15: 			$r = $this->x[$nm];
   16: 			echo "Returning: $r\n";
   17: 			return $r;
   18: 		} 
   19: 		else {
   20: 			echo "Nothing!\n";
   21: 		}
   22: 	}
   23: 
   24: 	function __set($nm, $val) {
   25: 		echo "Setting [$nm] to $val\n";
   26:                     
   27: 		if (isset($this->x[$nm])) {
   28: 			$this->x[$nm] = $val;
   29: 			echo "OK!\n";
   30: 		} 
   31: 		else {
   32: 			echo "Not OK!\n";
   33: 		}
   34: 	}
   35: }
   36: 
   37: $foo = new Setter();
   38: 
   39: // this doesn't go through __set()... should it?
   40: $foo->n = 1;
   41: 
   42: // the rest are fine...
   43: $foo->a = 100;
   44: $foo->a++;
   45: $foo->z++;
   46: var_dump($foo);
   47:         
   48: ?>
   49: --EXPECTF--
   50: Setting [a] to 100
   51: OK!
   52: Getting [a]
   53: Returning: 100
   54: Setting [a] to 101
   55: OK!
   56: Getting [z]
   57: Nothing!
   58: Setting [z] to 1
   59: Not OK!
   60: object(setter)#%d (2) {
   61:   ["n"]=>
   62:   int(1)
   63:   ["x"]=>
   64:   array(3) {
   65:     ["a"]=>
   66:     int(101)
   67:     ["b"]=>
   68:     int(2)
   69:     ["c"]=>
   70:     int(3)
   71:   }
   72: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>