From 5a186cc932524d85ce602e152a79d5201a4eb3b5 Mon Sep 17 00:00:00 2001 From: valmat Date: Sun, 9 Mar 2014 20:17:20 +0600 Subject: issue #23: Fixed loop for an objects contains no public properties --- Examples/CppClassesInPhp/check_map.php | 69 ++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 23 deletions(-) (limited to 'Examples') diff --git a/Examples/CppClassesInPhp/check_map.php b/Examples/CppClassesInPhp/check_map.php index cdd5345..2103bac 100644 --- a/Examples/CppClassesInPhp/check_map.php +++ b/Examples/CppClassesInPhp/check_map.php @@ -5,21 +5,51 @@ * */ -class cl1 { - public $qwe = 45615; - public $asd = "asdasdasd"; - public $zxcv = "Привет!"; // check UTF-8 chars +class cl0 { + public $cl0_float = 3.14; + public $cl0_str1 = 'public str1'; + private $cl0_str2 = 'private str2'; + protected $cl0_str3 = 'protected str3'; +} + +class cl1 extends cl0 implements arrayaccess +{ + static $cl1_static = 'static prop'; + + const CL1_CONST = 'const prop'; + + public $cl1_num = 45615; + public $cl1_str = "Public Prop"; + + private $cl1_pp1 = "Private Prop1"; + private $cl1_pp2 = "Private Prop2"; + + protected $cl1_prp1 = "Protected Prop1"; + protected $cl1_prp2 = "Protected Prop2"; + public function fn($a) { echo $a; } - function __destruct(){ - echo 'cl1::__destruct'; - } function __toString() { return 'I\'m class cl1'; } + public function offsetSet($offset, $value) { + if (!is_null($offset)) { + $this->$offset = $value; + } + } + public function offsetExists($offset) { + return isset($this->$offset); + } + public function offsetUnset($offset) { + unset($this->$offset); + } + public function offsetGet($offset) { + return isset($this->$offset) ? $this->$offset : null; + } + } class emptyClass {} @@ -34,10 +64,15 @@ $arr = array( new cl1(), '%'=>'%$%$%', ); -//$arr = array(5,17,'qwe' => 'qweqweqweqw',4=>88,'17'=>'170','1'=>4, new cl1()); -//$arr = array(3.14,2.7,11,0,500); + +$arr = new cl1(); + +$arr[5] = 55; +$arr['strstr'] = 'strstrstrstrstrstr'; + +//$arr = new emptyClass(); //$arr = array(); -//$arr = new cl1(); + $q = new MyClass(); @@ -47,17 +82,5 @@ var_export($arr); // Works for objects and arrays $q->loopObject($arr); - -$q->loopObject(new emptyClass()); - - -/* -// Validation removal (i.e. do I need to use zval_add_ref(value);) -echo "\nunset(\$arr):"; -unset($arr); -echo "\nunset(\$q):"; -unset($q); -*/ - - +//$q->loopObject($arr); -- cgit v1.2.3