helly Fri Oct 24 14:24:29 2003 EDT
Modified files:
/ZendEngine2ZEND_CHANGES zend_API.c zend_execute_API.c
/php-src/ext/socketssockets.c
Log:
Zend/ZEND_CHANGES
Index: ZendEngine2/ZEND_CHANGES
diff -u ZendEngine2/ZEND_CHANGES:1.61 ZendEngine2/ZEND_CHANGES:1.62
--- ZendEngine2/ZEND_CHANGES:1.61 Tue Oct 21 02:41:26 2003
+++ ZendEngine2/ZEND_CHANGESFri Oct 24 14:24:27 2003
@@ -651,6 +651,79 @@
TBD: Respect visibility: Show protected only when inside class
method and only otherwise public properties only.
+ Each class whose instances can be iterated with foreach should
+ implement the empty interface 'Traversable'. Hence any object
+ that says it implements 'Traversable' can be used with forach.
+
+ The interfaces 'IteratorAggregate' and 'Iterator' allow to specify
+ how class objects are iterated in PHP code. The first of them simply
+ has a method 'getIterator' which must return an array or an object
+ that either implements the interface 'Iterator' or is instantiated
+ from an internal class that can be iterated.
+
+ Example:
+
+?php
+class ObjectIterator implements Iterator {
+
+private $obj;
+private $num;
+
+function __construct($obj) {
+$this-obj = $obj;
+}
+function rewind() {
+$this-num = 0;
+}
+function hasMore() {
+return $this-num $this-obj-max;
+}
+function key() {
+return $this-num;
+}
+function current() {
+switch($this-num) {
+case 0: return 1st;
+case 1: return 2nd;
+case 2: return 3rd;
+default: return $this-num.th;
+}
+}
+function next() {
+$this-num++;
+}
+}
+
+class Oject implements IteratorAggregate {
+
+public $max = 3;
+
+function getIterator() {
+return new ObjectIterator($this);
+}
+}
+
+$obj = new Object;
+
+// this foreach ...
+foreach($obj as $key = $val) {
+echo $key = $val\n;
+}
+
+// matches the following 7 lines with the for directive.
+$it = $obj-getIterator();
+for($it-rewind(); $it-hasMore(); $it-next) {
+$key = $it-current();
+$val = $it-key();
+echo $key = $val\n;
+}
+unset($it);
+?
+
+ The matching for directive is very intersting here since it shows
+ the use of all abstract methods declared in the interfaces Iterator
+ and IteratorAggregate respectively.
+
* __METHOD__
The pseudo constant __METHOD__ shows the current class and method
Index: ZendEngine2/zend_API.c
diff -u ZendEngine2/zend_API.c:1.221 ZendEngine2/zend_API.c:1.222
--- ZendEngine2/zend_API.c:1.221Wed Oct 22 15:59:58 2003
+++ ZendEngine2/zend_API.c Fri Oct 24 14:24:27 2003
@@ -18,7 +18,7 @@
+--+
*/
-/* $Id: zend_API.c,v 1.221 2003/10/22 19:59:58 helly Exp $ */
+/* $Id: zend_API.c,v 1.222 2003/10/24 18:24:27 helly Exp $ */
#include zend.h
#include zend_execute.h
@@ -1588,8 +1588,23 @@
return 1;
lcname = zend_str_tolower_dup(Z_STRVAL_P(callable),
Z_STRLEN_P(callable));
- if (zend_hash_exists(EG(function_table), lcname,
Z_STRLEN_P(callable)+1))
+ if (zend_hash_exists(EG(function_table), lcname,
Z_STRLEN_P(callable)+1)) {
retval = 1;
+ } else {
+ char *func_pos;
+ if ((func_pos=strstr(lcname, ::))) {
+ int lcclass_len = (int)(func_pos - lcname);
+ char *lcclass = estrndup(lcname, lcclass_len);
+ zend_class_entry **ce;
+
+ if (zend_lookup_class(lcclass, lcclass_len,
ce TSRMLS_CC) == SUCCESS) {
+ int func_len = Z_STRLEN_P(callable) -
lcclass_len - 2;
+ func_pos += 2;
+ retval =
zend_hash_exists((*ce)-function_table, func_pos, func_len + 1) ? 1 : 0;
+ }
+