diff options
author | SVN Migration <svn@php.net> | 2003-10-30 10:07:27 +0000 |
---|---|---|
committer | SVN Migration <svn@php.net> | 2003-10-30 10:07:27 +0000 |
commit | e00288b5b25766c2292b2e45596b9bc25d910111 (patch) | |
tree | d217ee89217ebab98202493d6820befb7bfdca6e /ext/spl | |
parent | 0b3fe789062221deb65f7c0b15c450d9bda9bcbb (diff) | |
download | php-git-php-5.0.0b2.tar.gz |
This commit was manufactured by cvs2svn to create tag 'php_5_0_0b2'.php-5.0.0b2
Diffstat (limited to 'ext/spl')
39 files changed, 0 insertions, 5091 deletions
diff --git a/ext/spl/CREDITS b/ext/spl/CREDITS deleted file mode 100755 index 8710aac550..0000000000 --- a/ext/spl/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -SPL -Marcus Boerger diff --git a/ext/spl/EXPERIMENTAL b/ext/spl/EXPERIMENTAL deleted file mode 100755 index e69de29bb2..0000000000 --- a/ext/spl/EXPERIMENTAL +++ /dev/null diff --git a/ext/spl/README b/ext/spl/README deleted file mode 100755 index 60c6d97425..0000000000 --- a/ext/spl/README +++ /dev/null @@ -1,88 +0,0 @@ -This is an extension that aims to implement some efficient data access -interfaces and classes. You'll find the classes documented using php -code in the file spl.php. - -There are special SPL interfaces that provides the ability to hook into -foreach and array reading/writng. By inheriting these interfaces, instances -of the resulting classes can be iterated using the foreach construct or -use array read write notation. - -Look into the examples subdirectory for some basic examples which will -demonstracte this. - -Also some classes of extensions like SQLite inherit SPL interfaces so that -they take advantage of the foreach or array overloading. - -1) Iterators - -Iterator is design pattern that allows to enumerate and list all elements of -a collection whatsoever using an oo protocol. The minimalistic Iterator needs -a method that returns the current value, a method that moves to the next value -and a method that checks whether or not the Iterator can provide more elements. - -In SPL this basich Iterator is defined by the interface spl_forward: - -interface spl_forward { - function current(); - function next(); - function has_more(); -} - -This basic Iterator does not allow to rewind itself nor does it in anyway -support to name the values by some kind association as key/value mappings -provided by the standard PHP arrays. All these additions to the basic Iterator -are done in specialized interfaces as described in detail in the file spl.php. - -SPL allows to hook into the engine opcodes that realize the foreach construct. -This construct normally works on arrays the following way. First it rewinds -the current array position to the beginning. Then it loops through the whole -array by first checking whether or not the end of the array is reached and -if not returning the current array value and or key. After that it move the -current array pointer forward and does starts the loop process again. As you -can see this perfectly maps to the interface spl_forward. So the foreach -hooking simply checks whether or not the variable passed to foreach is an -object of a class implementing the interface spl_forward. The foreach hook -can be activated by --enable-spl-foreach which is on by default. - -class it implements spl_forward... -$obj = new it(); -foreach($obj as $value) ... - -2) Arrays - -Arrays in general, not specifically PHP arrays, provide a collection of pairs -normally referred to as key and value. A PHP object consists of properties and -a class type specifing the methods available for the object. SPL now allows -this to be combined using the spl_array_<xy> interfaces. - -The minimalistic array interface is spl_array_read which only support reading: - -interface spl_array_read { - function exists($key); - function get($key); -} - -Any instance of a class that implements spl_array_read can be used with array -read notation when the corresponding hook is activated --enable-spl-array-read. - -class ar implements spl_array_read... -$obj = new ar(); -$value = $obj[$key]; - -SPL also supports the write notation by the interface spl_array_access: - -interface spl_array_access extends spl_array_read { - function set($value, $index); -} - -When the array write hook is activated by --enable-spl-array-write the -following can be done: - -class ar implements spl_array_access... -$obj = new ar(); -$value = $obj[$key]; -$obj[$key] = $value; - -However this hook should only be activated when it is made use of, since it -slows down noticeable. That is the case because first there is some not used -overhead and second the overhead is in one the most often used opcodes.
\ No newline at end of file diff --git a/ext/spl/README.PROFILING b/ext/spl/README.PROFILING deleted file mode 100755 index 67e55b3717..0000000000 --- a/ext/spl/README.PROFILING +++ /dev/null @@ -1,98 +0,0 @@ -SQLite is the first extension that makes use of SPL automatically by simply -enabling both. - -SQLite offers four access strategies: -1) sqlite_query + sqlite_fetch_array -2) sqlite_unbuffered_query + sqlite_fetch_array -3) sqlite_query + iterators (sqlite_current) -4) sqlite_unbuffered_query + iterators (sqlite_current) -5) sqlite_array_query - -1) and 3) do "over eager evaluating" since they fetch all rows directly. - -2) does "eager evaluating". It always fetches the next row but doesn't -keep the current row, so that it must be stored elsewhere if it must be -accessed more then once. For instance this happens when you need to access -columns separately. - -4) does "eager evaluating". But in contrast to 2) it keeps the current row -hence its name. - -There is no efficient way for "lazy or just in time evaluating" so 4) should -be the best case. And 4) also enables the foreach trick. - -5) does a full buffered fetch and returns the complete result into an array. -As long as you only have a few rows in your result this is very fast and of -course it is very flexible since you can access any column/row as often you -like and in any order you like. But it needs to store the full result what -is called "eager evaluating". - -Speedwise analysis: - -I compared a database using a table of round about 200 rows with 3 columns. -I measured the case where 10 rows are returned, since i guess this is a -value often taken as default list size in web applications. However i did -that 10 times because the loop initialization is the slowest part of foreach -overloading. Since we are only interested in the relative effect foreach -overloading has i stiped the setup part and used a query result iteration -that does nothing. That means i run 'php -h' in the profiler first and then -profiled every single case. For completeness i also computed the values -including the setup process. - -Method, without setup, with setup -1) 100.00% 100.00% -2) 89.32% 97.16% -3) 88.35% 96.90% - -Furthermore i did some more checks and found out that the loop process using -foreach overloading (2) takes a constant time while it seems that the time -needed to add more rows to the array increases with the number of rows being -already in the array. As a result (2) is faster than (3) after round about 45 -rows. - -The loop codes used: - -1) Unbuffered query - -<?php -$dbname = dirname(__FILE__).'/profile.sqlite'; -$db = sqlite_factory($dbname); - -for ($i = 0; $i < 10; $i++) { - $res = $db->unbuffered_query("SELECT idx, name, size from files LIMIT 10", SQLITE_NUM); - while ($res->has_more()) { -// var_dump($res->current()); - $res->current(); - $res->next(); - } -} -echo "DONE!\n"; -?> - -2) Unbuffered query using foreach overloading - -<?php -$dbname = dirname(__FILE__).'/profile.sqlite'; -$db = sqlite_factory($dbname); - -for ($i = 0; $i < 10; $i++) { - foreach($db->unbuffered_query("SELECT idx, name, size from files LIMIT 10", SQLITE_NUM) as $row) { -// var_dump($row); - } -} -echo "DONE!\n"; -?> - -3) Array query method - -<?php -$dbname = dirname(__FILE__).'/profile.sqlite'; -$db = sqlite_factory($dbname); - -for ($i = 0; $i < 10; $i++) { - foreach($db->array_query("SELECT idx, name, size from files LIMIT 10", SQLITE_NUM) as $row) { -// var_dump($row); - } -} -echo "DONE!\n"; -?>
\ No newline at end of file diff --git a/ext/spl/TODO b/ext/spl/TODO deleted file mode 100755 index 5311ef6c11..0000000000 --- a/ext/spl/TODO +++ /dev/null @@ -1,13 +0,0 @@ -This is the ToDo of ext/spl: - -- spl::array_access cals set() which is supposed to return a value. - Currently you *must* return a value even when it is not used. - $obj[$idx] = $val; // doesn't use the return value - $x = $obj[$idx] = $val; // here it is used - Since array_access.phpt is a test with a return value there - should be a test without a return value. Maybe an error message - is required in case there is no return value. - -- spl::array_access_ex is not completely done and not tested. - -If you have further questions: mailto:helly@php.net diff --git a/ext/spl/config.m4 b/ext/spl/config.m4 deleted file mode 100755 index bce2b4f43a..0000000000 --- a/ext/spl/config.m4 +++ /dev/null @@ -1,43 +0,0 @@ -dnl $Id$ -dnl config.m4 for extension SPL - -PHP_ARG_ENABLE(spl, enable SPL suppport, -[ --disable-spl Enable Standard PHP Library], yes) - -dnl first enable/disable all hooks - -PHP_ARG_ENABLE(spl-hook-all, enable all hooks, -[ --enable-spl-hook-all SPL: Enable all hooks]) - -dnl now all single enable/disable for hooks - -PHP_ARG_ENABLE(spl-foreach, enable hook on foreach, -[ --disable-spl-foreach SPL: Disable hook on forach], yes) - -PHP_ARG_ENABLE(spl-array-read, enable hook on array read, -[ --enable-spl-array-read SPL: Enable hook on array read]) - -PHP_ARG_ENABLE(spl-array-write, enable hook on array write, -[ --enable-spl-array-write SPL: Enable hook on array write (+read)]) - -dnl last do checks on hooks - -if test "$PHP_SPL" != "no"; then - if test "$PHP_SPL_HOOK_ALL" != "no" -o "$PHP_SPL_FOREACH" != "no"; then - AC_DEFINE(SPL_FOREACH, 1, [Activate opcode hook on foreach]) - PHP_SPL="yes" - fi - if test "$PHP_SPL_HOOK_ALL" != "no" -o "$PHP_SPL_ARRAY_READ" != "no" -o "$PHP_SPL_ARRAY_WRITE" != "no"; then - AC_DEFINE(SPL_ARRAY_READ, 1, [Activate opcode hook on array read]) - PHP_SPL="yes" - fi - if test "$PHP_SPL_HOOK_ALL" != "no" -o "$PHP_SPL_ARRAY_WRITE" != "no"; then - AC_DEFINE(SPL_ARRAY_WRITE, 1, [Activate opcode hook on array write]) - PHP_SPL="yes" - fi -fi - -if test "$PHP_SPL" != "no"; then - AC_DEFINE(HAVE_SPL, 1, [Whether you want SPL (Standard Php Library) support]) - PHP_NEW_EXTENSION(spl, php_spl.c spl_functions.c spl_engine.c spl_foreach.c spl_array.c spl_directory.c, $ext_shared) -fi diff --git a/ext/spl/examples/dba_array.php b/ext/spl/examples/dba_array.php deleted file mode 100755 index ebbe5a7bac..0000000000 --- a/ext/spl/examples/dba_array.php +++ /dev/null @@ -1,79 +0,0 @@ -<?php - -/* dba array utility - * - * Usage php dba_dump <file> <handler> <key> [<value>] - * - * If <value> is specified then <key> is set to <value> in <file>. - * Else the value of <key> is printed only. - * - * Note: configure with --enable-dba - * - * (c) Marcus Boerger - */ - -class dba_array implements spl_array_access { - private $db; - - function __construct($file, $handler) - { - $this->db = dba_popen($file, "c", $handler); - if (!$this->db) { - throw new exception("Databse could not be opened"); - } - } - - function __destruct() - { - dba_close($this->db); - } - - function get($name) - { - $data = dba_fetch($name, $this->db); - if($data) { - if (ini_get('magic_quotes_runtime')) { - $data = stripslashes($data); - } - return unserialize($data); - } - else - { - return NULL; - } - } - - function set($name, $value) - { - dba_replace($name, serialize($value), $this->db); - return $value; - } - - function exists($name) - { - return dba_exists($name, $this->db); - } -} - -try { - if ($argc > 2) { - $dba = new dba_array($argv[1], $argv[2]); - if ($dba && $argc > 3) { - if ($argc > 4) { - $dba[$argv[3]] = $argv[4]; - } - var_dump(array('Index' => $argv[3], 'Value' => $dba[$argv[3]])); - } - $dba = NULL; - } - else - { - echo "Not enough parameters\n"; - exit(1); - } -} -catch (exception $err) { - var_dump($err); - exit(1); -} -?>
\ No newline at end of file diff --git a/ext/spl/examples/dba_dump.php b/ext/spl/examples/dba_dump.php deleted file mode 100755 index 77ea2008bd..0000000000 --- a/ext/spl/examples/dba_dump.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php - -/* dba dump utility - * - * Usage: php dba_dump <file> <handler> [<regex>] - * - * Show all groups in the ini file specified by <file>. - * The regular expression <regex> is used to filter the by setting name. - * - * Note: configure with --enable-dba - * - * (c) Marcus Boerger - */ - -require_once("dba_reader.inc"); -require_once("key_filter.inc"); - -$db = new dba_reader($argv[1], $argv[2]); - -if ($argc>3) { - $db = new key_filter($db, $argv[3]); -} - -foreach($db as $key => $val) { - echo "'$key' => '$val'\n"; -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/dba_reader.inc b/ext/spl/examples/dba_reader.inc deleted file mode 100755 index b8c7365f97..0000000000 --- a/ext/spl/examples/dba_reader.inc +++ /dev/null @@ -1,83 +0,0 @@ -<?php - -/** - * @brief This implements an dba iterator. - * @author Marcus Boerger - * @version 1.0 - */ -class dba_reader implements spl_sequence_assoc -{ - - private $db = NULL; - private $key = false; - private $val = false; - - /** - * Open database $file with $handler in read only mode. - * - * @param file Database file to open. - * @param handler Handler to use for database access. - */ - function __construct($file, $handler) { - $this->db = dba_open($file, 'r', $handler); - } - - /** - * Close database. - */ - function __destruct() { - if ($this->db) { - dba_close($this->db); - } - } - - /** - * Rewind to first element. - */ - function rewind() { - if ($this->db) { - $this->key = dba_firstkey($this->db); - } - } - - /** - * @return Current data. - */ - function current() { - return $this->val; - } - - /** - * Move to next element. - * - * @return void - */ - function next() { - if ($this->db) { - $this->key = dba_nextkey($this->db); - if ($this->key !== false) { - $this->val = dba_fetch($this->key, $this->db); - } - } - } - - /** - * @return Whether more elements are available. - */ - function hasMore() { - if ($this->db && $this->key !== false) { - return true; - } else { - return false; - } - } - - /** - * @return Current key. - */ - function key() { - return $this->key; - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/filter.inc b/ext/spl/examples/filter.inc deleted file mode 100755 index 1cab580edd..0000000000 --- a/ext/spl/examples/filter.inc +++ /dev/null @@ -1,96 +0,0 @@ -<?php - -/** - * @brief Regular expression filter for string iterators - * @author Marcus Boerger - * @version 1.0 - * - * Instances of this class act as a filter around iterators whose elements - * are strings. In other words you can put an iterator into the constructor - * and the instance will only return elements which match the given regular - * expression. - */ -class filter implements spl_forward -{ - protected $it; - protected $regex; - protected $curr; - - /** - * Constructs a filter around an iterator whose elemnts are strings. - * If the given iterator is of type spl_sequence then its rewind() - * method is called. - * - * @param it Object that implements at least spl_forward - * @patam regex Regular expression used as a filter. - */ - function __construct(spl_forward $it, $regex) { - if ($it instanceof spl_sequence) { - $it->rewind(); - } - $this->it = $it; - $this->regex = $regex; - $this->fetch(); - } - - /** - * Destruct the iterator. - */ - function __destruct() { - unset($this->it); - } - - protected function accept($curr) { - return ereg($this->regex, $curr); - } - - /** - * Fetch next element and store it. - * - * @return void - */ - protected function fetch() { - $this->curr = false; - while ($this->it->hasMore()) { - $curr = $this->it->current(); - if ($this->accept($curr)) { - $this->curr = $curr; - return; - } - $this->it->next(); - }; - } - - /** - * Move to next element - * - * @return void - */ - function next() { - $this->it->next(); - $this->fetch(); - } - - /** - * @return Whether more elements are available - */ - function hasMore() { - return $this->curr !== false; - } - - /** - * @return The current value - */ - function current() { - return $this->curr; - } - - /** - * hidden __clone - */ - protected function __clone() { - // disallow clone - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/filter_tree.php b/ext/spl/examples/filter_tree.php deleted file mode 100755 index 8ee4cef556..0000000000 --- a/ext/spl/examples/filter_tree.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -/* tree view example - * - * Usage: php filter_tree.php <path> <regex> - * - * Simply specify the path to tree with parameter <path>. - * The regular expression <regex> is used to filter the tree. - * - * (c) Marcus Boerger - */ - -require_once("sub_dir.inc"); -require_once("filter.inc"); - -foreach(new filter(new sub_dir($argv[1]), $argv[2]) as $f) { - echo "$f\n"; -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/ini_groups.php b/ext/spl/examples/ini_groups.php deleted file mode 100755 index 1909e87c2d..0000000000 --- a/ext/spl/examples/ini_groups.php +++ /dev/null @@ -1,65 +0,0 @@ -<?php - -/* List groups within an ini file - * - * Usage: php dba_dump <file> [<regex>] - * - * Show all groups in the ini file specified by <file>. - * The regular expression <regex> is used to filter the result. - * - * Note: configure with --enable-dba - * - * (c) Marcus Boerger - */ - -require_once("dba_reader.inc"); -require_once("key_filter.inc"); - -/** - * @brief Class to iterate all groups within an ini file. - * @author Marcus Boerger - * @version 1.0 - * - * Using this class you can iterator over all groups of a ini file. - * - * This class uses a 'is-a' relation to key_filter in contrast to a 'has-a' - * relation. Doing so both current() and key() methods must be overwritten. - * If it would use a 'has-a' relation there would be much more to type... - * but for puritists that would allow correctness in so far as then no - * key() would be needed. - */ -class ini_groups extends key_filter -{ - /** - * Construct an ini file group iterator from a filename. - * - * @param file Ini file to open. - */ - function __construct($file) { - parent::__construct(new dba_reader($file, 'inifile'), '^\[.*\]$'); - } - - /** - * @return The current group. - */ - function current() { - return substr(parent::key(),1,-1); - } - - /** - * @return The current group. - */ - function key() { - return substr(parent::key(),1,-1); - } -} - -$it = new ini_groups($argv[1]); -if ($argc>2) { - $it = new key_filter($it, $argv[2]); -} -foreach($it as $group) { - echo "$group\n"; -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/key_filter.inc b/ext/spl/examples/key_filter.inc deleted file mode 100755 index 47ceed2246..0000000000 --- a/ext/spl/examples/key_filter.inc +++ /dev/null @@ -1,102 +0,0 @@ -<?php - -/** - * @brief Regular expression filter for string iterators - * @author Marcus Boerger - * @version 1.0 - * - * Instances of this class act as a filter around iterators whose elements - * are strings. In other words you can put an iterator into the constructor - * and the instance will only return elements which match the given regular - * expression. - */ -class key_filter implements spl_forward_assoc -{ - protected $it; - protected $regex; - protected $key; - protected $curr; - - /** - * Constructs a filter around an iterator whose elemnts are strings. - * If the given iterator is of type spl_sequence then its rewind() - * method is called. - * - * @param it Object that implements at least spl_forward - * @patam regex Regular expression used as a filter. - */ - function __construct(spl_forward $it, $regex) { - if ($it instanceof spl_sequence) { - $it->rewind(); - } - $this->it = $it; - $this->regex = $regex; - $this->fetch(); - } - - /** - * Destruct the iterator. - */ - function __destruct() { - unset($this->it); - } - - /** - * Fetch next element and store it. - * - * @return void - */ - protected function fetch() { - $this->key = false; - $this->curr = false; - while ($this->it->hasMore()) { - $key = $this->it->key(); - if (ereg($this->regex, $key)) { - $this->key = $key; - $this->curr = $this->it->current(); - return; - } - $this->it->next(); - }; - } - - /** - * Move to next element - * - * @return void - */ - function next() { - $this->it->next(); - $this->fetch(); - } - - /** - * @return Whether more elements are available - */ - function hasMore() { - return $this->key !== false; - } - - /** - * @return The current key - */ - function key() { - return $this->key; - } - - /** - * @return The current value - */ - function current() { - return $this->curr; - } - - /** - * hidden __clone - */ - protected function __clone() { - // disallow clone - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/sub_dir.inc b/ext/spl/examples/sub_dir.inc deleted file mode 100755 index 2e869e78d4..0000000000 --- a/ext/spl/examples/sub_dir.inc +++ /dev/null @@ -1,134 +0,0 @@ -<?php - -/** - * @brief Subdirectory aware directory iterator. - * @author Marcus Boerger - * @version 1.0 - * - * This directory iterator recursively returns all files and directories - * within a given path. - */ -class sub_dir implements spl_sequence -{ - protected $adir = array(); - protected $cnt = 0; - protected $path = ''; - protected $curr = ''; - protected $nodots = true; - - /** - * Construct a directory from a path. - * - * @param path The path to iterate. - * @param nodots Whether or not to display the entries '.' and '..'. - */ - function __construct($path, $nodots = true, $graph = false) { - $this->cnt = 0; - $this->path = $path; - $this->nodots = $nodots; - $this->graph = $graph; - } - - /** - * Rewind the directory. - * - * @return void - */ - function rewind() { - while($this->cnt) { - unset($this->adir[$this->cnt--]); - } - $dir = new spl_dir($this->path); - $dir->path = ""; - $this->adir[1] = $dir; - $this->cnt = 1; - if ($this->nodots) { - while ($dir->hasMore()) { - $ent = $dir->current(); - if ($ent != '.' && $ent != '..') { - break; - } - $dir->next(); - } - } - } - - /** - * Move to net dir or file entry. - * - * @return void - */ - function next() { - if ($this->cnt) { - $dir = $this->adir[$this->cnt]; - $ent = $dir->current(); - $path = $dir->getPath().'/'.$ent; - if ($ent != '.' && $ent != '..' && is_dir($path)) { - $new = new spl_dir($path); - $new->path = $dir->path.$ent.'/'; - $new->cnt = $this->cnt++; - $this->adir[$this->cnt] = $new; - if ($this->nodots) { - $dir->has_more = false; - while ($new->hasMore()) { - $ent = $new->current(); - if ($ent != '.' && $ent != '..') { - $dir->has_more = true; - break; - } - $new->next(); - } - } else { - $dir->has_more = $dir->hasMore(); - } - } - $dir->next(); - } - } - - /** - * @return Whether more dirs or files entries are available. - */ - function hasMore() { - while ($this->cnt) { - $dir = $this->adir[$this->cnt]; - if ($dir->hasMore()) { - return true; - } - unset($this->adir[$this->cnt--]); - } - return false; - } - - /** - * @return The current dir or file entry. - */ - function current() { - if ($this->cnt) { - if ($this->graph) { - $prefix = ''; - for ($i = 1; $i < $this->cnt; $i++) { - $dir = $this->adir[$i]; - $prefix .= $dir->hasMore() ? '| ' : ' '; - } - $dir = $this->adir[$this->cnt]; - $ent = $dir->current(); - $prefix .= $dir->hasMore() ? '+-' : '\-'; - return $prefix . $ent; - } else { - $dir = $this->adir[$this->cnt]; - return $dir->path . $dir->current(); - } - } - throw new exception("No more elements available"); - } - - /** - * Hidden __clone - */ - protected function __clone() { - // disallow clone - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/tree.php b/ext/spl/examples/tree.php deleted file mode 100755 index 176c286076..0000000000 --- a/ext/spl/examples/tree.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php - -/* tree view example - * - * Usage: php tree.php <path> - * - * Simply specify the path to tree with parameter <path>. - * - * (c) Marcus Boerger - */ - -require_once("sub_dir.inc"); - -foreach(new sub_dir($argv[1], true, isset($argv[2]) ? $argv[2] : false) as $f) { - echo "$f\n"; -} - -?>
\ No newline at end of file diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c deleted file mode 100755 index 7617f3fa9e..0000000000 --- a/ext/spl/php_spl.c +++ /dev/null @@ -1,326 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" -#include "php_spl.h" -#include "spl_functions.h" -#include "spl_engine.h" -#include "spl_foreach.h" -#include "spl_array.h" - -#ifdef COMPILE_DL_SPL -ZEND_GET_MODULE(spl) -#endif - -ZEND_DECLARE_MODULE_GLOBALS(spl) - -/* {{{ spl_functions - */ -function_entry spl_functions[] = { - PHP_FE(spl_classes, NULL) - PHP_FE(class_parents, NULL) - PHP_FE(class_implements, NULL) - {NULL, NULL, NULL} -}; -/* }}} */ - -/* {{{ spl_module_entry - */ -zend_module_entry spl_module_entry = { - STANDARD_MODULE_HEADER, - "spl", - spl_functions, - PHP_MINIT(spl), - PHP_MSHUTDOWN(spl), - PHP_RINIT(spl), - PHP_RSHUTDOWN(spl), - PHP_MINFO(spl), - "0.2", - STANDARD_MODULE_PROPERTIES -}; -/* }}} */ - -zend_class_entry *spl_ce_iterator; -zend_class_entry *spl_ce_forward; -zend_class_entry *spl_ce_assoc; -zend_class_entry *spl_ce_sequence; -zend_class_entry *spl_ce_forward_assoc; -zend_class_entry *spl_ce_sequence_assoc; -zend_class_entry *spl_ce_array_read; -zend_class_entry *spl_ce_array_access; - -/* {{{ spl_functions_none - */ -function_entry spl_functions_none[] = { - {NULL, NULL, NULL} -}; -/* }}} */ - -/* {{{ spl_init_globals - */ -static void spl_init_globals(zend_spl_globals *spl_globals) -{ -#ifdef SPL_FOREACH - ZEND_EXECUTE_HOOK(ZEND_FE_RESET); - ZEND_EXECUTE_HOOK(ZEND_FE_FETCH); - ZEND_EXECUTE_HOOK(ZEND_SWITCH_FREE); -#endif - -#if defined(SPL_ARRAY_READ) | defined(SPL_ARRAY_WRITE) - ZEND_EXECUTE_HOOK(ZEND_FETCH_DIM_R); - ZEND_EXECUTE_HOOK(ZEND_FETCH_DIM_W); - ZEND_EXECUTE_HOOK(ZEND_FETCH_DIM_RW); -#endif - -#ifdef SPL_ARRAY_WRITE - ZEND_EXECUTE_HOOK(ZEND_ASSIGN_DIM); - ZEND_EXECUTE_HOOK(ZEND_UNSET_DIM_OBJ); -#endif /* SPL_ARRAY_WRITE */ -} -/* }}} */ - -PHP_FUNCTION(spl_abstract) {} - -#define SPL_ABSTRACT_FE(class, name, arg_info) \ - { #name, ZEND_FN(spl_abstract), arg_info, sizeof(arg_info)/sizeof(struct _zend_arg_info)-1, ZEND_ACC_ABSTRACT|ZEND_ACC_PUBLIC }, - -static -ZEND_BEGIN_ARG_INFO(arginfo_one_param, 0) - ZEND_ARG_INFO(0, index) -ZEND_END_ARG_INFO(); - -static -ZEND_BEGIN_ARG_INFO(arginfo_two_params, 0) - ZEND_ARG_INFO(0, index) - ZEND_ARG_INFO(0, value) -ZEND_END_ARG_INFO(); - -function_entry spl_funcs_iterator[] = { - SPL_ABSTRACT_FE(iterator, newIterator, NULL) - {NULL, NULL, NULL} -}; - -function_entry spl_funcs_forward[] = { - SPL_ABSTRACT_FE(forward, current, NULL) - SPL_ABSTRACT_FE(forward, next, NULL) - SPL_ABSTRACT_FE(forward, hasMore, NULL) - {NULL, NULL, NULL} -}; - -function_entry spl_funcs_sequence[] = { - SPL_ABSTRACT_FE(sequence, rewind, NULL) - {NULL, NULL, NULL} -}; - -function_entry spl_funcs_assoc[] = { - SPL_ABSTRACT_FE(assoc, key, NULL) - {NULL, NULL, NULL} -}; - -function_entry *spl_funcs_forward_assoc = NULL; -function_entry *spl_funcs_sequence_assoc = NULL; - -function_entry spl_funcs_array_read[] = { - SPL_ABSTRACT_FE(array_read, get, arginfo_one_param) - SPL_ABSTRACT_FE(array_read, exists, arginfo_one_param) - {NULL, NULL, NULL} -}; - -function_entry spl_funcs_array_access[] = { - SPL_ABSTRACT_FE(array_access, set, arginfo_two_params) - SPL_ABSTRACT_FE(array_access, del, arginfo_one_param) - {NULL, NULL, NULL} -}; - -/* {{{ PHP_MINIT_FUNCTION(spl) - */ -PHP_MINIT_FUNCTION(spl) -{ - ZEND_INIT_MODULE_GLOBALS(spl, spl_init_globals, NULL); - - REGISTER_SPL_INTERFACE(iterator); - - REGISTER_SPL_INTERFACE(forward); - - REGISTER_SPL_INTERFACE(sequence); - REGISTER_SPL_IMPLEMENT(sequence, forward); - - REGISTER_SPL_INTERFACE(assoc); - - REGISTER_SPL_INTERFACE(forward_assoc); - REGISTER_SPL_IMPLEMENT(forward_assoc, assoc); - REGISTER_SPL_IMPLEMENT(forward_assoc, forward); - - REGISTER_SPL_INTERFACE(sequence_assoc); - REGISTER_SPL_IMPLEMENT(sequence_assoc, forward_assoc); - REGISTER_SPL_IMPLEMENT(sequence_assoc, sequence); - - REGISTER_SPL_INTERFACE(array_read); - - REGISTER_SPL_INTERFACE(array_access); - REGISTER_SPL_IMPLEMENT(array_access, array_read); - - PHP_MINIT(spl_array)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(spl_directory)(INIT_FUNC_ARGS_PASSTHRU); - - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_RINIT_FUNCTION(spl) - */ -PHP_RINIT_FUNCTION(spl) -{ - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_RSHUTDOWN_FUNCTION(spl) - */ -PHP_RSHUTDOWN_FUNCTION(spl) -{ - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_MSHUTDOWN_FUNCTION(spl) - */ -PHP_MSHUTDOWN_FUNCTION(spl) -{ - SPL_DEBUG(fprintf(stderr, "%s\n", "Shutting down SPL");) - -#ifdef SPL_FOREACH - ZEND_EXECUTE_HOOK_RESTORE(ZEND_FE_RESET); - ZEND_EXECUTE_HOOK_RESTORE(ZEND_FE_FETCH); - ZEND_EXECUTE_HOOK_RESTORE(ZEND_SWITCH_FREE); -#endif - -#if defined(SPL_ARRAY_READ) | defined(SPL_ARRAY_WRITE) - ZEND_EXECUTE_HOOK_RESTORE(ZEND_FETCH_DIM_R); - ZEND_EXECUTE_HOOK_RESTORE(ZEND_FETCH_DIM_W); - ZEND_EXECUTE_HOOK_RESTORE(ZEND_FETCH_DIM_RW); -#endif - -#ifdef SPL_ARRAY_WRITE - ZEND_EXECUTE_HOOK_RESTORE(ZEND_ASSIGN_DIM); -#endif /* SPL_ARRAY_WRITE */ - - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_MINFO(spl) - */ -PHP_MINFO_FUNCTION(spl) -{ -#ifdef SPL_FOREACH - char *foreach = "beta"; -#else /* SPL_ARRAY_WRITE */ - char *foreach = "beta, not hooked"; -#endif -#ifdef SPL_ARRAY_READ - char *array_read = "beta"; -#else /* SPL_ARRAY_WRITE */ - char *array_read = "beta, not hooked"; -#endif -#ifdef SPL_ARRAY_WRITE - char *array_write = "beta"; -#else /* SPL_ARRAY_WRITE */ - char *array_write = "beta, not hooked"; -#endif /* SPL_ARRAY_WRITE */ - - php_info_print_table_start(); - php_info_print_table_header(2, "SPL support", "enabled"); - php_info_print_table_row(2, "iterator", foreach); - php_info_print_table_row(2, "forward", foreach); - php_info_print_table_row(2, "sequence", foreach); - php_info_print_table_row(2, "assoc", foreach); - php_info_print_table_row(2, "forward_assoc", foreach); - php_info_print_table_row(2, "sequence_assoc", foreach); - php_info_print_table_row(2, "array_read", array_read); - php_info_print_table_row(2, "array_access", array_write); - php_info_print_table_end(); -} -/* }}} */ - -/* {{{ class_parents - */ -PHP_FUNCTION(class_parents) -{ - zval *obj; - zend_class_entry *parent_class; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) { - RETURN_FALSE; - } - array_init(return_value); - parent_class = Z_OBJCE_P(obj)->parent; - while (parent_class) { - spl_add_class_name(return_value, parent_class TSRMLS_CC); - parent_class = parent_class->parent; - } -} -/* }}} */ - -/* {{{ class_implements - */ -PHP_FUNCTION(class_implements) -{ - zval *obj; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) { - RETURN_FALSE; - } - array_init(return_value); - spl_add_interfaces(return_value, Z_OBJCE_P(obj) TSRMLS_CC); -} -/* }}} */ - -#define SPL_ADD_CLASS(class_name) \ - spl_add_classes(&spl_ce_ ## class_name, return_value TSRMLS_CC) - -/* {{{ spl_classes */ -PHP_FUNCTION(spl_classes) -{ - array_init(return_value); - - SPL_ADD_CLASS(iterator); - SPL_ADD_CLASS(forward); - SPL_ADD_CLASS(sequence); - SPL_ADD_CLASS(assoc); - SPL_ADD_CLASS(forward_assoc); - SPL_ADD_CLASS(sequence_assoc); - SPL_ADD_CLASS(array_read); - SPL_ADD_CLASS(array_access); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/php_spl.h b/ext/spl/php_spl.h deleted file mode 100755 index b8de833022..0000000000 --- a/ext/spl/php_spl.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -#ifndef PHP_SPL_H -#define PHP_SPL_H - -#include "php.h" -#include <stdarg.h> - -#if 0 -#define SPL_DEBUG(x) x -#else -#define SPL_DEBUG(x) -#endif - -extern zend_module_entry spl_module_entry; -#define phpext_spl_ptr &spl_module_entry - -#if defined(PHP_WIN32) && !defined(COMPILE_DL_SPL) -#undef phpext_spl -#define phpext_spl NULL -#endif - -PHP_MINIT_FUNCTION(spl); -PHP_MSHUTDOWN_FUNCTION(spl); -PHP_RINIT_FUNCTION(spl); -PHP_RSHUTDOWN_FUNCTION(spl); -PHP_MINFO_FUNCTION(spl); - -#define ZEND_EXECUTE_HOOK_PTR(name) \ - opcode_handler_t handler_ ## name - -#define ZEND_EXECUTE_HOOK(name) \ - spl_globals->handler_ ## name = zend_opcode_handlers[name]; \ - zend_opcode_handlers[name] = spl_handler_ ## name - -#define ZEND_EXECUTE_HOOK_RESTORE(name) \ - zend_opcode_handlers[name] = SPL_G(handler_ ## name) - -#define ZEND_EXECUTE_HOOK_ORIGINAL(name) \ - return SPL_G(handler_ ## name)(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU) - -#define ZEND_EXECUTE_HOOK_FUNCTION(name) \ - int spl_handler_ ## name(ZEND_OPCODE_HANDLER_ARGS) - -ZEND_BEGIN_MODULE_GLOBALS(spl) -#ifdef SPL_FOREACH - ZEND_EXECUTE_HOOK_PTR(ZEND_FE_RESET); - ZEND_EXECUTE_HOOK_PTR(ZEND_FE_FETCH); - ZEND_EXECUTE_HOOK_PTR(ZEND_SWITCH_FREE); -#endif -#if defined(SPL_ARRAY_READ) | defined(SPL_ARRAY_WRITE) - ZEND_EXECUTE_HOOK_PTR(ZEND_FETCH_DIM_R); - ZEND_EXECUTE_HOOK_PTR(ZEND_FETCH_DIM_W); - ZEND_EXECUTE_HOOK_PTR(ZEND_FETCH_DIM_RW); -#endif -#ifdef SPL_ARRAY_WRITE - ZEND_EXECUTE_HOOK_PTR(ZEND_ASSIGN_DIM); - ZEND_EXECUTE_HOOK_PTR(ZEND_UNSET_DIM_OBJ); -#endif -ZEND_END_MODULE_GLOBALS(spl) - -#ifdef ZTS -# define SPL_G(v) TSRMG(spl_globals_id, zend_spl_globals *, v) -extern int spl_globals_id; -#else -# define SPL_G(v) (spl_globals.v) -extern zend_spl_globals spl_globals; -#endif - -extern zend_class_entry *spl_ce_iterator; -extern zend_class_entry *spl_ce_forward; -extern zend_class_entry *spl_ce_sequence; -extern zend_class_entry *spl_ce_assoc; -extern zend_class_entry *spl_ce_forward_assoc; -extern zend_class_entry *spl_ce_sequence_assoc; -extern zend_class_entry *spl_ce_array_read; -extern zend_class_entry *spl_ce_array_access; - -PHP_FUNCTION(spl_classes); -PHP_FUNCTION(class_parents); -PHP_FUNCTION(class_implements); - -PHP_MINIT_FUNCTION(spl_array); -PHP_MINIT_FUNCTION(spl_directory); - -#endif /* PHP_SPL_H */ - -/* - * Local Variables: - * c-basic-offset: 4 - * tab-width: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl.php b/ext/spl/spl.php deleted file mode 100755 index 2edde96154..0000000000 --- a/ext/spl/spl.php +++ /dev/null @@ -1,340 +0,0 @@ -<?php - -/* Standard PHP Library - * - * (c) M.Boerger 2003 - */ - -/*! \brief Interface to foreach() construct - * - * Any class that implements this interface can for example be used as - * the input parameter to foreach() calls which would normally be an - * array. - * - * The class must implement the function new_iterator which must return - * an object which implements the interface spl_forward. - * - * \see spl_forward, spl_sequence, spl_forward_assoc, spl_sequence_assoc - */ -interface spl_iterator { - - /*! \brief Create a new iterator - * - * \return an object that implements the interface spl_forward. - */ - function new_iterator(); -} - -/*! \brief Simple forward iterator - * - * Any class that implements this interface can be used as the - * return of a foreach interface. And hence the class itself - * can be used as a parameter to be iterated (normally an array). - * - * \code - class c implements spl_iterator, spl_forward { - private $num = 0; - function new_iterator() { - $this->num = 0; - return $this; - } - function current() { - return $this->num; - } - function next() { - $this->num++; - } - function has_more() { - return $this->num < 5; - } - } - - $t = new c(); - - foreach($t as $num) { - echo "$num\n"; - } - \endcode - * - * A very interesting usage scenario are for example database queries. - * Without this interface you need to do it without foreach or fetch the - * whole rowset into an array. - * - * In the above code the class implements both the foreach and the - * forward interface. Doing this you cannot have nested foreach calls. - * If you need this you must split the two parts. - * - * \code - class c implements spl_iterator { - public $max = 3; - function new_iterator() { - return new c_iter($this); - } - } - class c_iter implements spl_forward { - private $obj; - private $num = 0; - function __construct($obj) { - $this->obj = $obj; - } - function current() { - return $this->num; - } - function next() { - $this->num++; - } - function has_more() { - return $this->num < $this->obj->max; - } - } - - $t = new c(); - - foreach($t as $outer) { - foreach($t as $inner) { - echo "$outer,$inner\n"; - } - } - \endcode - * - * You can also use this interface with the for() construct. - * - * \code - class c implements spl_iterator { - public $max = 3; - function new_iterator() { - return new c_iter($this); - } - } - class c_iter implements spl_forward { - private $obj; - private $num = 0; - function __construct($obj) { - $this->obj = $obj; - } - function current() { - return $this->num; - } - function next() { - $this->num++; - } - function has_more() { - return $this->num < $this->obj->max; - } - } - - $t = new c(); - - for ($iter = $t->new_iterator(); $iter->has_more(); $iter->next()) { - echo $iter->current() . "\n"; - } - \endcode - */ -interface spl_forward { - - /*! \brief Retrieve the current currentent - * - * \return \c mixed current element or \c false if no more elements - */ - function current(); - - /*! \brief Forward to next element. - */ - function next(); - - /*! \brief Check if more elements are available. - * - * This method is meant to be called right after calls to rewind() or - * next(). When you use foreach hooking then this is done automatically - * but you can use it inside a for loop yourself: - * \code - for(; $it->has_more(); $it->next()) { ... } - \endcode - * - * \return \c bool whether or not more elements are available - */ - function has_more(); -} - -/*! \brief A restartable iterator. - * - * This iterator allows you to implement a restartable iterator. That - * means the iterator can be rewind to the first element after accessing - * any number of elements. - * - * \note If you use sequence in foreach then rewind() will be called - * first. - */ -interface spl_sequence extends spl_forward { - - /*! Restart the sequence by positioning it to the first element. - */ - function rewind(); -} - -/*! \brief associative interface - * - * This interface allows to implement associative iterators - * and containers. - */ -interface spl_assoc { - - /*! \brief Retrieve the current elements key - * - * \return \c mixed current key or \c false if no more elements - */ - function key(); -} - -/*! \brief associative foreach() interface - * - * This interface extends the forward interface to support keys. - * With this interface you can do: - * \code - $t = new c(); - foreach($t as $key => $elem). - \endcode - */ -interface spl_assoc_forward implements spl_forward, spl_assoc { -} - -/*! \brief associative sequence - */ -interface spl_assoc_sequence implements spl_sequence, spl_assoc { -} - -/*! \brief array read only access for objects - */ -interface spl_array_read { - - /*! Check whether or not the given index exists. - * The returned value is interpreted as converted to bool. - */ - function exists($index); - - /*! Read the value at position $index. - * This function is only beeing called if exists() returns true. - */ - function get($index); -} - -/*! \brief array read/write access for objects. - * - * The following example shows how to use interface array_access: - * \code - class array_emulation implemets spl_array_access { - private $ar = array(); - function exists($index) { - return array_key_exists($index, $this->ar); - } - function get($index) { - return $this->ar[$index]; - } - function set($index, $value) { - $this->ar[$index] = $value; - } - function del($index) { - unset($this->ar[$index]); - } - } - \endcode - */ -interface spl_array_access implements spl_array_read { - - /*! Set the value identified by $index to $value. - */ - function set($index, $value); - - /*! Delete (unset) the value identified by $index. - */ - function del($index); -} - -/*! \brief An array wrapper - * - * This array wrapper allows to recursively iterate over Arrays and Objects. - * - * \see spl_array_it - */ -class spl_array implements spl_iterator { - - /*! Construct a new array iterator from anything that has a hash table. - * That is any Array or Object. - * - * \param $array the array to use. - */ - function __construct($array); - - /*! \copydoc spl_iterator::new_iterator - */ - function new_iterator(); -} - -/*! \brief An array iterator - * - * This iterator allows to unset and modify values and keys while iterating - * over Arrays and Objects. - * - * To use this class you must instanciate spl_array. - */ -class spl_array_it implements spl_sequence_assoc { - - /*! Construct a new array iterator from anything that has a hash table. - * That is any Array or Object. - * - * \param $array the array to use. - */ - private function __construct($array); - - /*! \copydoc spl_sequence::rewind - */ - function rewind(); - - /*! \copydoc spl_forward::current - */ - function current(); - - /*! \copydoc spl_assoc::key - */ - function key(); - - /*! \copydoc spl_forward::next - */ - function next(); - - /*! \copydoc spl_forward::has_more - */ - function has_more(); -} - -/*! \brief Directory iterator - */ -class spl_dir implements spl_sequence { - - /*! Construct a directory iterator from a path-string. - * - * \param $path directory to iterate. - */ - function __construct($path); - - /*! \copydoc spl_sequence::rewind - */ - function rewind(); - - /*! \copydoc spl_forward::current - */ - function current(); - - /*! \copydoc spl_forward::next - */ - function next(); - - /*! \copydoc spl_forward::has_more - */ - function has_more(); - - /*! \return The opened path. - */ - function get_path(); -} -?>
\ No newline at end of file diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c deleted file mode 100755 index 95132cb6c2..0000000000 --- a/ext/spl/spl_array.c +++ /dev/null @@ -1,772 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" -#include "zend_compile.h" - -#include "php_spl.h" -#include "spl_functions.h" -#include "spl_engine.h" -#include "spl_array.h" - -#define DELETE_ZVAL(z) \ - if ((z)->refcount < 2) { \ - zval_dtor(z); \ - FREE_ZVAL(z); /* maybe safe_free_zval_ptr is needed for the uninitialised things */ \ - } - -#define DELETE_RET_ZVAL(z) \ - if ((z)->refcount < 3) { \ - zval_dtor(z); \ - FREE_ZVAL(z); /* maybe safe_free_zval_ptr is needed for the uninitialised things */ \ - } - -#define AI_PTR_2_PTR_PTR(ai) \ - (ai).ptr_ptr = &((ai).ptr) - -/* {{{ spl_fetch_dimension_address */ -int spl_fetch_dimension_address(znode *result, znode *op1, znode *op2, temp_variable *Ts, int type TSRMLS_DC) -{ - zval **obj; - zend_class_entry *obj_ce; - spl_is_a is_a; - - obj = spl_get_zval_ptr_ptr(op1, Ts TSRMLS_CC); - - if (!obj || (obj_ce = spl_get_class_entry(*obj TSRMLS_CC)) == NULL) { - return 1; - } - - is_a = spl_implements(obj_ce); - - if (is_a & SPL_IS_A_ARRAY_READ) { - zval **retval = &(T(result->u.var).var.ptr); - zval *dim = spl_get_zval_ptr(op2, Ts, &EG(free_op2) TSRMLS_CC); - zval *exists; - - spl_call_method_1(obj, obj_ce, NULL, "exists", sizeof("exists")-1, &exists, dim); - if (!i_zend_is_true(exists)) { - if (type == BP_VAR_R || type == BP_VAR_RW) { - SEPARATE_ZVAL(&dim); - convert_to_string_ex(&dim); - zend_error(E_NOTICE, "Undefined index: %s", Z_STRVAL_P(dim)); - DELETE_ZVAL(dim); - } - if (type == BP_VAR_R || type == BP_VAR_IS) { - DELETE_RET_ZVAL(exists); - *retval = &EG(error_zval); - (*retval)->refcount++; - FREE_OP(Ts, op2, EG(free_op2)); - SELECTIVE_PZVAL_LOCK(*retval, result); - return 0; - } - } - DELETE_RET_ZVAL(exists); - if (type == BP_VAR_R || type == BP_VAR_IS) { - spl_call_method_1(obj, obj_ce, NULL, "get", sizeof("get")-1, retval, dim); - } - FREE_OP(Ts, op2, EG(free_op2)); - return 0; - } - return 1; -} -/* }}} */ - -/* {{{ ZEND_EXECUTE_HOOK_FUNCTION(ZEND_FETCH_DIM_R) */ -#ifdef SPL_ARRAY_READ -ZEND_EXECUTE_HOOK_FUNCTION(ZEND_FETCH_DIM_R) -{ - if (!spl_fetch_dimension_address(&EX(opline)->result, &EX(opline)->op1, &EX(opline)->op2, EX(Ts), BP_VAR_R TSRMLS_CC)) - { - if (EX(opline)->extended_value == ZEND_FETCH_ADD_LOCK) { - spl_pzval_lock_func(*EX_T(EX(opline)->op1.u.var).var.ptr_ptr); - } - spl_unlock_zval_ptr_ptr(&EX(opline)->op1, EX(Ts) TSRMLS_CC); - - AI_PTR_2_PTR_PTR(EX_T(EX(opline)->result.u.var).var); - NEXT_OPCODE(); - } - ZEND_EXECUTE_HOOK_ORIGINAL(ZEND_FETCH_DIM_R); -} -#endif -/* }}} */ - -/* {{{ ZEND_EXECUTE_HOOK_FUNCTION(ZEND_FETCH_DIM_W) */ -#ifdef SPL_ARRAY_READ -ZEND_EXECUTE_HOOK_FUNCTION(ZEND_FETCH_DIM_W) -{ - if (!spl_fetch_dimension_address(&EX(opline)->result, &EX(opline)->op1, &EX(opline)->op2, EX(Ts), BP_VAR_W TSRMLS_CC)) - { - spl_unlock_zval_ptr_ptr(&EX(opline)->op1, EX(Ts) TSRMLS_CC); - - NEXT_OPCODE(); - } - ZEND_EXECUTE_HOOK_ORIGINAL(ZEND_FETCH_DIM_W); -} -#endif -/* }}} */ - -/* {{{ ZEND_EXECUTE_HOOK_FUNCTION(ZEND_FETCH_DIM_RW) */ -#ifdef SPL_ARRAY_READ -ZEND_EXECUTE_HOOK_FUNCTION(ZEND_FETCH_DIM_RW) -{ - if (!spl_fetch_dimension_address(&EX(opline)->result, &EX(opline)->op1, &EX(opline)->op2, EX(Ts), BP_VAR_RW TSRMLS_CC)) - { - spl_unlock_zval_ptr_ptr(&EX(opline)->op1, EX(Ts) TSRMLS_CC); - - NEXT_OPCODE(); - } - ZEND_EXECUTE_HOOK_ORIGINAL(ZEND_FETCH_DIM_RW); -} -#endif -/* }}} */ - -static inline zval **spl_get_obj_zval_ptr_ptr(znode *op, temp_variable *Ts, int type TSRMLS_DC) -{ - if (op->op_type == IS_UNUSED) { - if (EG(This)) { - /* this should actually never be modified, _ptr_ptr is modified only when - the object is empty */ - return &EG(This); - } else { - zend_error(E_ERROR, "Using $this when not in object context"); - } - } - return spl_get_zval_ptr_ptr(op, Ts TSRMLS_CC); -} - -/* {{{ ZEND_EXECUTE_HOOK_FUNCTION(ZEND_ASSIGN_DIM) */ -#ifdef SPL_ARRAY_WRITE -ZEND_EXECUTE_HOOK_FUNCTION(ZEND_ASSIGN_DIM) -{ - zval **obj; - zend_class_entry *obj_ce; - spl_is_a is_a; - - obj = spl_get_obj_zval_ptr_ptr(&EX(opline)->op1, EX(Ts), 0 TSRMLS_CC); - - if (!obj || (obj_ce = spl_get_class_entry(*obj TSRMLS_CC)) == NULL) { - ZEND_EXECUTE_HOOK_ORIGINAL(ZEND_ASSIGN_DIM); - } - - is_a = spl_implements(obj_ce); - - if (is_a & SPL_IS_A_ARRAY_ACCESS) { - znode *op2 = &EX(opline)->op2; - zval *index = spl_get_zval_ptr(op2, EX(Ts), &EG(free_op2), BP_VAR_R); - zval *free_value; - zend_op *value_op = EX(opline)+1; - zval *value = spl_get_zval_ptr(&value_op->op1, EX(Ts), &free_value, BP_VAR_R); - zval tmp; - zval *retval; - - spl_unlock_zval_ptr_ptr(&EX(opline)->op1, EX(Ts) TSRMLS_CC); - - /* here we are sure we are dealing with an object */ - switch (op2->op_type) { - case IS_CONST: - /* already a constant string */ - break; - case IS_VAR: - tmp = *index; - zval_copy_ctor(&tmp); - convert_to_string(&tmp); - index = &tmp; - break; - case IS_TMP_VAR: - convert_to_string(index); - break; - } - - /* separate our value if necessary */ - if (value_op->op1.op_type == IS_TMP_VAR) { - zval *orig_value = value; - - ALLOC_ZVAL(value); - *value = *orig_value; - value->is_ref = 0; - value->refcount = 0; - } - - spl_call_method_2(obj, obj_ce, NULL, "set", sizeof("set")-1, &retval, index, value); - - if (index == &tmp) { - zval_dtor(index); - } - - FREE_OP(Ts, op2, EG(free_op2)); - if (&EX(opline)->result) { - if (retval->refcount < 2) { - zend_error(E_WARNING, "Method %s::set() did not return a value, using input value", obj_ce->name); - EX_T(EX(opline)->result.u.var).var.ptr = value; - SELECTIVE_PZVAL_LOCK(value, &EX(opline)->result); - DELETE_RET_ZVAL(retval); - } else { - SELECTIVE_PZVAL_LOCK(retval, &EX(opline)->result); - EX_T(EX(opline)->result.u.var).var.ptr = retval; - retval->refcount--; - } - EX_T(EX(opline)->result.u.var).var.ptr_ptr = NULL; - } else { - DELETE_RET_ZVAL(retval); - } - - EX(opline)++; - NEXT_OPCODE(); - } - ZEND_EXECUTE_HOOK_ORIGINAL(ZEND_ASSIGN_DIM); -} -#endif -/* }}} */ - -/* {{{ ZEND_EXECUTE_HOOK_FUNCTION(ZEND_UNSET_DIM_OBJ) */ -#ifdef SPL_ARRAY_WRITE -ZEND_EXECUTE_HOOK_FUNCTION(ZEND_UNSET_DIM_OBJ) -{ - zval **obj; - zend_class_entry *obj_ce; - spl_is_a is_a; - - if (EX(opline)->extended_value != ZEND_UNSET_DIM) { - ZEND_EXECUTE_HOOK_ORIGINAL(ZEND_UNSET_DIM_OBJ); - } - - obj = spl_get_obj_zval_ptr_ptr(&EX(opline)->op1, EX(Ts), 0 TSRMLS_CC); - - if (!obj || (obj_ce = spl_get_class_entry(*obj TSRMLS_CC)) == NULL) { - ZEND_EXECUTE_HOOK_ORIGINAL(ZEND_UNSET_DIM_OBJ); - } - - is_a = spl_implements(obj_ce); - - if (is_a & SPL_IS_A_ARRAY_ACCESS) { - znode *op2 = &EX(opline)->op2; - zval *index = spl_get_zval_ptr(op2, EX(Ts), &EG(free_op2), BP_VAR_R); - zval tmp; - zval *retval; - - spl_unlock_zval_ptr_ptr(&EX(opline)->op1, EX(Ts) TSRMLS_CC); - - /* here we are sure we are dealing with an object */ - switch (op2->op_type) { - case IS_CONST: - /* already a constant string */ - break; - case IS_VAR: - tmp = *index; - zval_copy_ctor(&tmp); - convert_to_string(&tmp); - index = &tmp; - break; - case IS_TMP_VAR: - convert_to_string(index); - break; - } - - spl_call_method_1(obj, obj_ce, NULL, "del", sizeof("del")-1, &retval, index); - - if (index == &tmp) { - zval_dtor(index); - } - - FREE_OP(Ts, op2, EG(free_op2)); - DELETE_RET_ZVAL(retval); - - NEXT_OPCODE(); - } - ZEND_EXECUTE_HOOK_ORIGINAL(ZEND_UNSET_DIM_OBJ); -} -#endif -/* }}} */ - -SPL_CLASS_FUNCTION(array, __construct); -SPL_CLASS_FUNCTION(array, newIterator); -SPL_CLASS_FUNCTION(array, rewind); -SPL_CLASS_FUNCTION(array, current); -SPL_CLASS_FUNCTION(array, key); -SPL_CLASS_FUNCTION(array, next); -SPL_CLASS_FUNCTION(array, hasMore); - -static -ZEND_BEGIN_ARG_INFO(arginfo_array___construct, 0) - ZEND_ARG_INFO(0, array) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_array_class_functions[] = { - SPL_CLASS_FE(array, __construct, arginfo_array___construct, ZEND_ACC_PUBLIC) - SPL_CLASS_FE(array, newIterator, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -static zend_function_entry spl_array_it_class_functions[] = { - SPL_CLASS_FE(array, __construct, arginfo_array___construct, ZEND_ACC_PRIVATE) - SPL_CLASS_FE(array, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_CLASS_FE(array, current, NULL, ZEND_ACC_PUBLIC) - SPL_CLASS_FE(array, key, NULL, ZEND_ACC_PUBLIC) - SPL_CLASS_FE(array, next, NULL, ZEND_ACC_PUBLIC) - SPL_CLASS_FE(array, hasMore, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -static zend_object_handlers spl_array_handlers; -static zend_class_entry * spl_ce_array; - -static zend_object_handlers spl_array_it_handlers; -static zend_class_entry * spl_ce_array_it; - -typedef struct _spl_array_object { - zend_object std; - zval *array; - HashPosition pos; -} spl_array_object; - -/* {{{ spl_array_object_dtor */ -static void spl_array_object_dtor(void *object, zend_object_handle handle TSRMLS_DC) -{ - spl_array_object *intern = (spl_array_object *)object; - - zend_hash_destroy(intern->std.properties); - FREE_HASHTABLE(intern->std.properties); - - if (!ZVAL_DELREF(intern->array)) { - zval_dtor(intern->array); - FREE_ZVAL(intern->array); - } - - efree(object); -} -/* }}} */ - -/* {{{ spl_array_object_new */ -static zend_object_value spl_array_object_new_ex(zend_class_entry *class_type, spl_array_object **obj, spl_array_object *orig TSRMLS_DC) -{ - zend_object_value retval; - spl_array_object *intern; - zval *tmp; - - intern = emalloc(sizeof(spl_array_object)); - memset(intern, 0, sizeof(spl_array_object)); - intern->std.ce = class_type; - *obj = intern; - - ALLOC_HASHTABLE(intern->std.properties); - zend_hash_init(intern->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - if (orig) { - intern->array = orig->array; - ZVAL_ADDREF(intern->array); - } else { - MAKE_STD_ZVAL(intern->array); - array_init(intern->array); - } - zend_hash_internal_pointer_reset_ex(HASH_OF(intern->array), &intern->pos); - - retval.handle = zend_objects_store_put(intern, spl_array_object_dtor, NULL TSRMLS_CC); - if (class_type == spl_ce_array_it) { - retval.handlers = &spl_array_it_handlers; - } else { - retval.handlers = &spl_array_handlers; - } - return retval; -} -/* }}} */ - -/* {{{ spl_array_object_new */ -static zend_object_value spl_array_object_new(zend_class_entry *class_type TSRMLS_DC) -{ - spl_array_object *tmp; - return spl_array_object_new_ex(class_type, &tmp, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ spl_array_object_clone */ -static zend_object_value spl_array_object_clone(zval *zobject TSRMLS_DC) -{ - zend_object_value new_obj_val; - zend_object *old_object; - zend_object *new_object; - zend_object_handle handle = Z_OBJ_HANDLE_P(zobject); - spl_array_object *intern; - - old_object = zend_objects_get_address(zobject TSRMLS_CC); - new_obj_val = spl_array_object_new_ex(old_object->ce, &intern, (spl_array_object*)old_object TSRMLS_CC); - new_object = &intern->std; - - zend_objects_clone_members(new_object, new_obj_val, old_object, handle TSRMLS_CC); - - return new_obj_val; -} -/* }}} */ - -/* {{{ spl_array_get_ce */ -static zend_class_entry *spl_array_get_ce(zval *object TSRMLS_DC) -{ - return spl_ce_array; -} -/* }}} */ - -/* {{{ spl_array_it_get_ce */ -static zend_class_entry *spl_array_it_get_ce(zval *object TSRMLS_DC) -{ - return spl_ce_array_it; -} -/* }}} */ - -/* {{{ spl_array_read_dimension */ -static zval *spl_array_read_dimension(zval *object, zval *offset TSRMLS_DC) -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - zval **retval; - long index; - - switch(Z_TYPE_P(offset)) { - case IS_STRING: - if (zend_symtable_find(HASH_OF(intern->array), Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void **) &retval) == FAILURE) { - zend_error(E_NOTICE,"Undefined index: %s", Z_STRVAL_P(offset)); - return EG(uninitialized_zval_ptr); - } else { - return *retval; - } - case IS_DOUBLE: - case IS_RESOURCE: - case IS_BOOL: - case IS_LONG: - if (offset->type == IS_DOUBLE) { - index = (long)Z_DVAL_P(offset); - } else { - index = Z_LVAL_P(offset); - } - if (zend_hash_index_find(HASH_OF(intern->array), index, (void **) &retval) == FAILURE) { - zend_error(E_NOTICE,"Undefined offset: %ld", Z_LVAL_P(offset)); - return EG(uninitialized_zval_ptr); - } else { - return *retval; - } - break; - default: - zend_error(E_WARNING, "Illegal offset type"); - return EG(uninitialized_zval_ptr); - } -} -/* }}} */ - -/* {{{ spl_array_write_dimension */ -static void spl_array_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC) -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - long index; - - switch(Z_TYPE_P(offset)) { - case IS_STRING: - zend_symtable_update(HASH_OF(intern->array), Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void**)&value, sizeof(void*), NULL); - return; - case IS_DOUBLE: - case IS_RESOURCE: - case IS_BOOL: - case IS_LONG: - if (offset->type == IS_DOUBLE) { - index = (long)Z_DVAL_P(offset); - } else { - index = Z_LVAL_P(offset); - } - add_index_zval(intern->array, index, value); - return; - default: - zend_error(E_WARNING, "Illegal offset type"); - return; - } -} -/* }}} */ - -/* {{{ spl_array_unset_dimension */ -static void spl_array_unset_dimension(zval *object, zval *offset TSRMLS_DC) -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - long index; - - switch(Z_TYPE_P(offset)) { - case IS_STRING: - if (zend_symtable_del(HASH_OF(intern->array), Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1) == FAILURE) { - zend_error(E_NOTICE,"Undefined index: %s", Z_STRVAL_P(offset)); - } - return; - case IS_DOUBLE: - case IS_RESOURCE: - case IS_BOOL: - case IS_LONG: - if (offset->type == IS_DOUBLE) { - index = (long)Z_DVAL_P(offset); - } else { - index = Z_LVAL_P(offset); - } - if (zend_hash_index_del(HASH_OF(intern->array), index) == FAILURE) { - zend_error(E_NOTICE,"Undefined offset: %ld", Z_LVAL_P(offset)); - } - return; - default: - zend_error(E_WARNING, "Illegal offset type"); - return; - } -} -/* }}} */ - -/* {{{ spl_array_get_properties */ -static HashTable *spl_array_get_properties(zval *object TSRMLS_DC) -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - - return HASH_OF(intern->array); -} -/* }}} */ - -/* {{{ PHP_MINIT_FUNCTION(spl_array) */ -PHP_MINIT_FUNCTION(spl_array) -{ - REGISTER_SPL_STD_CLASS_EX(array, spl_array_object_new, spl_array_class_functions); - REGISTER_SPL_IMPLEMENT(array, iterator); - memcpy(&spl_array_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - spl_array_handlers.clone_obj = spl_array_object_clone; - spl_array_handlers.get_class_entry = spl_array_get_ce; - spl_array_handlers.read_dimension = spl_array_read_dimension; - spl_array_handlers.write_dimension = spl_array_write_dimension; - spl_array_handlers.unset_dimension = spl_array_unset_dimension; - spl_array_handlers.get_properties = spl_array_get_properties; - - REGISTER_SPL_STD_CLASS_EX(array_it, spl_array_object_new, spl_array_it_class_functions); - REGISTER_SPL_IMPLEMENT(array_it, sequence_assoc); - memcpy(&spl_array_it_handlers, &spl_array_handlers, sizeof(zend_object_handlers)); - spl_array_it_handlers.get_class_entry = spl_array_it_get_ce; - - return SUCCESS; -} -/* }}} */ - -/* {{{ proto void spl_array::__construct(array|object ar = array()) - proto void spl_array_it::__construct(array|object ar = array()) - Cronstructs a new array iterator from a path. */ -SPL_CLASS_FUNCTION(array, __construct) -{ - zval *object = getThis(); - spl_array_object *intern; - zval **array; - - if (ZEND_NUM_ARGS() == 0) { - return; /* nothing to do */ - } -/* exceptions do not work yet - php_set_error_handling(EH_THROW, zend_exception_get_default() TSRMLS_CC);*/ - - if (ZEND_NUM_ARGS() > 1 || zend_get_parameters_ex(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - if (!HASH_OF(*array)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed variable is not an array or object, using empty array instead"); - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return; - } - intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - zval_dtor(intern->array); - FREE_ZVAL(intern->array); - intern->array = *array; - ZVAL_ADDREF(intern->array); - - zend_hash_internal_pointer_reset_ex(HASH_OF(intern->array), &intern->pos); - - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto spl_array_it|NULL spl_array::newIterator() - Create a new iterator from a spl_array instance */ -SPL_CLASS_FUNCTION(array, newIterator) -{ - zval *object = getThis(); - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - spl_array_object *iterator; - HashTable *aht = HASH_OF(intern->array); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - return; - } - - return_value->type = IS_OBJECT; - return_value->value.obj = spl_array_object_new_ex(spl_ce_array_it, &iterator, intern TSRMLS_CC); - return_value->refcount = 1; - return_value->is_ref = 1; -} -/* }}} */ - -/* {{{ spl_hash_pos_exists */ -ZEND_API int spl_hash_pos_exists(spl_array_object * intern TSRMLS_DC) -{ - HashTable *ht = HASH_OF(intern->array); - Bucket *p; - -/* IS_CONSISTENT(ht);*/ - -/* HASH_PROTECT_RECURSION(ht);*/ - p = ht->pListHead; - while (p != NULL) { - if (p == intern->pos) { - return SUCCESS; - } - p = p->pListNext; - } -/* HASH_UNPROTECT_RECURSION(ht); */ - zend_hash_internal_pointer_reset_ex(HASH_OF(intern->array), &intern->pos); - return FAILURE; -} -/* }}} */ - -/* {{{ proto void spl_array_it::rewind() - Rewind array back to the start */ -SPL_CLASS_FUNCTION(array, rewind) -{ - zval *object = getThis(); - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - HashTable *aht = HASH_OF(intern->array); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - return; - } - - zend_hash_internal_pointer_reset_ex(aht, &intern->pos); -} -/* }}} */ - -/* {{{ proto mixed|false spl_array_it::current() - Return current array entry */ -SPL_CLASS_FUNCTION(array, current) -{ - zval *object = getThis(); - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - zval **entry; - HashTable *aht = HASH_OF(intern->array); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - return; - } - - if (intern->array->is_ref && spl_hash_pos_exists(intern TSRMLS_CC) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and internal position is no longer valid"); - RETURN_FALSE; - } - - if (zend_hash_get_current_data_ex(aht, (void **) &entry, &intern->pos) == FAILURE) { - RETURN_FALSE; - } - *return_value = **entry; - zval_copy_ctor(return_value); -} -/* }}} */ - -/* {{{ proto mixed|false spl_array_it::key() - Return current array key */ -SPL_CLASS_FUNCTION(array, key) -{ - zval *object = getThis(); - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - char *string_key; - uint string_length; - ulong num_key; - HashTable *aht = HASH_OF(intern->array); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - return; - } - - if (intern->array->is_ref && spl_hash_pos_exists(intern TSRMLS_CC) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and internal position is no longer valid"); - RETURN_FALSE; - } - - switch (zend_hash_get_current_key_ex(aht, &string_key, &string_length, &num_key, 0, &intern->pos)) { - case HASH_KEY_IS_STRING: - RETVAL_STRINGL(string_key, string_length - 1, 1); - break; - case HASH_KEY_IS_LONG: - RETVAL_LONG(num_key); - break; - case HASH_KEY_NON_EXISTANT: - return; - } -} -/* }}} */ - -/* {{{ proto void spl_array_it::next() - Move to next entry */ -SPL_CLASS_FUNCTION(array, next) -{ - zval *object = getThis(); - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - HashTable *aht = HASH_OF(intern->array); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - return; - } - - if (intern->array->is_ref && spl_hash_pos_exists(intern TSRMLS_CC) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and internal position is no longer valid"); - } else { - zend_hash_move_forward_ex(aht, &intern->pos); - } -} -/* }}} */ - -/* {{{ proto bool spl_array_it::hasMore() - Check whether array contains more entries */ -SPL_CLASS_FUNCTION(array, hasMore) -{ - zval *object = getThis(); - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - HashTable *aht = HASH_OF(intern->array); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - return; - } - - if (intern->pos && intern->array->is_ref && spl_hash_pos_exists(intern TSRMLS_CC) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and internal position is no longer valid"); - RETURN_FALSE; - } else { - RETURN_BOOL(zend_hash_has_more_elements_ex(aht, &intern->pos) == SUCCESS); - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl_array.h b/ext/spl/spl_array.h deleted file mode 100755 index 840a9627eb..0000000000 --- a/ext/spl/spl_array.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -#ifndef SPL_ARRAY_H -#define SPL_ARRAY_H - -#include "php.h" -#include "php_spl.h" - -#ifdef SPL_ARRAY_READ -ZEND_EXECUTE_HOOK_FUNCTION(ZEND_FETCH_DIM_R); -ZEND_EXECUTE_HOOK_FUNCTION(ZEND_FETCH_DIM_W); -ZEND_EXECUTE_HOOK_FUNCTION(ZEND_FETCH_DIM_RW); -#endif - -#ifdef SPL_ARRAY_WRITE -ZEND_EXECUTE_HOOK_FUNCTION(ZEND_ASSIGN_DIM); -ZEND_EXECUTE_HOOK_FUNCTION(ZEND_UNSET_DIM_OBJ); -#endif - -#endif /* SPL_ARRAY_H */ - -/* - * Local Variables: - * c-basic-offset: 4 - * tab-width: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c deleted file mode 100755 index 045e5d4368..0000000000 --- a/ext/spl/spl_directory.c +++ /dev/null @@ -1,275 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" -#include "zend_compile.h" -#include "zend_default_classes.h" - -#include "php_spl.h" -#include "spl_functions.h" -#include "spl_engine.h" -#include "spl_foreach.h" - -#include "php.h" -#include "fopen_wrappers.h" - -SPL_CLASS_FUNCTION(dir, __construct); -SPL_CLASS_FUNCTION(dir, rewind); -SPL_CLASS_FUNCTION(dir, current); -SPL_CLASS_FUNCTION(dir, next); -SPL_CLASS_FUNCTION(dir, hasMore); -SPL_CLASS_FUNCTION(dir, getPath); - -static -ZEND_BEGIN_ARG_INFO(arginfo_dir___construct, 0) - ZEND_ARG_INFO(0, path) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_dir_class_functions[] = { - SPL_CLASS_FE(dir, __construct, arginfo_dir___construct, ZEND_ACC_PUBLIC) - SPL_CLASS_FE(dir, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_CLASS_FE(dir, current, NULL, ZEND_ACC_PUBLIC) - SPL_CLASS_FE(dir, next, NULL, ZEND_ACC_PUBLIC) - SPL_CLASS_FE(dir, hasMore, NULL, ZEND_ACC_PUBLIC) - SPL_CLASS_FE(dir, getPath, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -static zend_object_handlers spl_dir_handlers; -static zend_class_entry *spl_ce_dir; - -typedef struct _spl_dir_object { - zend_object std; - php_stream *dirp; - php_stream_dirent entry; - char *path; -} spl_dir_object; - -/* {{{ spl_dir_object_dtor */ -static void spl_dir_object_dtor(void *object, zend_object_handle handle TSRMLS_DC) -{ - spl_dir_object *intern = (spl_dir_object *)object; - - zend_hash_destroy(intern->std.properties); - FREE_HASHTABLE(intern->std.properties); - - if (intern->path) { - efree(intern->path); - } - if (intern->dirp) { - php_stream_close(intern->dirp); - } - efree(object); -} -/* }}} */ - -/* {{{ spl_dir_object_new */ -static zend_object_value spl_dir_object_new_ex(zend_class_entry *class_type, spl_dir_object **obj TSRMLS_DC) -{ - zend_object_value retval; - spl_dir_object *intern; - zval *tmp; - - intern = emalloc(sizeof(spl_dir_object)); - memset(intern, 0, sizeof(spl_dir_object)); - intern->std.ce = class_type; - *obj = intern; - - ALLOC_HASHTABLE(intern->std.properties); - zend_hash_init(intern->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(intern, spl_dir_object_dtor, NULL TSRMLS_CC); - retval.handlers = &spl_dir_handlers; - return retval; -} -/* }}} */ - -/* {{{ spl_dir_object_new */ -static zend_object_value spl_dir_object_new(zend_class_entry *class_type TSRMLS_DC) -{ - spl_dir_object *tmp; - return spl_dir_object_new_ex(class_type, &tmp TSRMLS_CC); -} -/* }}} */ - -/* {{{ spl_dir_open */ -static void spl_dir_open(spl_dir_object* intern, char *path TSRMLS_DC) -{ - /* we are using EH_THORW so REPORT_ERRORS results in exceptions */ - intern->dirp = php_stream_opendir(path, ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL); - - intern->path = estrdup(path); - - if (intern->dirp == NULL) { - /* throw exception: should've been already happened */ - intern->entry.d_name[0] = '\0'; - } else { - if (!php_stream_readdir(intern->dirp, &intern->entry)) { - intern->entry.d_name[0] = '\0'; - } - } -} -/* }}} */ - -/* {{{ spl_dir_object_clone */ -static zend_object_value spl_dir_object_clone(zval *zobject TSRMLS_DC) -{ - zend_object_value new_obj_val; - zend_object *old_object; - zend_object *new_object; - zend_object_handle handle = Z_OBJ_HANDLE_P(zobject); - spl_dir_object *intern; - - old_object = zend_objects_get_address(zobject TSRMLS_CC); - new_obj_val = spl_dir_object_new_ex(old_object->ce, &intern TSRMLS_CC); - new_object = &intern->std; - - spl_dir_open(intern, ((spl_dir_object*)old_object)->path TSRMLS_CC); - - zend_objects_clone_members(new_object, new_obj_val, old_object, handle TSRMLS_CC); - - return new_obj_val; -} -/* }}} */ - -/* {{{ spl_dir_get_ce */ -static zend_class_entry *spl_dir_get_ce(zval *object TSRMLS_DC) -{ - return spl_ce_dir; -} -/* }}} */ - -/* {{{ PHP_MINIT_FUNCTION(spl_directory) */ -PHP_MINIT_FUNCTION(spl_directory) -{ - REGISTER_SPL_STD_CLASS_EX(dir, spl_dir_object_new, spl_dir_class_functions); - REGISTER_SPL_IMPLEMENT(dir, sequence); - memcpy(&spl_dir_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - spl_dir_handlers.clone_obj = spl_dir_object_clone; - spl_dir_handlers.get_class_entry = spl_dir_get_ce; - - return SUCCESS; -} -/* }}} */ - -/* {{{ proto void __construct(string path) - Cronstructs a new dir iterator from a path. */ -SPL_CLASS_FUNCTION(dir, __construct) -{ - zval *object = getThis(); - spl_dir_object *intern; - char *path; - long len; - - php_set_error_handling(EH_THROW, zend_exception_get_default() TSRMLS_CC); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &len) == FAILURE) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return; - } - - intern = (spl_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - spl_dir_open(intern, path TSRMLS_CC); - - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto void rewind() - Rewind dir back to the start */ -SPL_CLASS_FUNCTION(dir, rewind) -{ - zval *object = getThis(); - spl_dir_object *intern = (spl_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - if (intern->dirp) { - php_stream_rewinddir(intern->dirp); - } - if (!intern->dirp || !php_stream_readdir(intern->dirp, &intern->entry)) { - intern->entry.d_name[0] = '\0'; - } -} -/* }}} */ - -/* {{{ proto string current() - Return current dir entry */ -SPL_CLASS_FUNCTION(dir, current) -{ - zval *object = getThis(); - spl_dir_object *intern = (spl_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - if (intern->dirp) { - RETURN_STRING(intern->entry.d_name, 1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto void next() - Move to next entry */ -SPL_CLASS_FUNCTION(dir, next) -{ - zval *object = getThis(); - spl_dir_object *intern = (spl_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - if (!intern->dirp || !php_stream_readdir(intern->dirp, &intern->entry)) { - intern->entry.d_name[0] = '\0'; - } -} -/* }}} */ - -/* {{{ proto string hasMore() - Check whether dir contains more entries */ -SPL_CLASS_FUNCTION(dir, hasMore) -{ - zval *object = getThis(); - spl_dir_object *intern = (spl_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - RETURN_BOOL(intern->entry.d_name[0] != '\0'); -} -/* }}} */ - -/* {{{ proto string getPath() - Return directory path */ -SPL_CLASS_FUNCTION(dir, getPath) -{ - zval *object = getThis(); - spl_dir_object *intern = (spl_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - RETURN_STRING(intern->path, 1); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/spl/spl_engine.c b/ext/spl/spl_engine.c deleted file mode 100755 index 349a599784..0000000000 --- a/ext/spl/spl_engine.c +++ /dev/null @@ -1,245 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" -#include "zend_compile.h" - -#include "php_spl.h" -#include "spl_functions.h" -#include "spl_engine.h" - -/* {{{ spl_instanciate */ -void spl_instanciate(zend_class_entry *pce, zval **object TSRMLS_DC) -{ - ALLOC_ZVAL(*object); - object_init_ex(*object, pce); - (*object)->refcount = 1; - (*object)->is_ref = 1; /* check if this can be hold always */ -} -/* }}} */ - -/* {{{ spl_instanciate_arg_ex2 */ -int spl_instanciate_arg_ex2(zend_class_entry *pce, zval **retval, zval *arg1, zval *arg2 TSRMLS_DC) -{ - zval *object; - - spl_instanciate(pce, &object TSRMLS_CC); - - retval = &EG(uninitialized_zval_ptr); - - spl_call_method(&object, pce, &pce->constructor, pce->constructor->common.function_name, strlen(pce->constructor->common.function_name), retval, 2, arg1, arg2 TSRMLS_CC); - *retval = object; - return 0; -} -/* }}} */ - -/* {{{ spl_get_zval_ptr_ptr - Remember to call spl_unlock_ptr_ptr when needed */ -zval ** spl_get_zval_ptr_ptr(znode *node, temp_variable *Ts TSRMLS_DC) -{ - if (node->op_type==IS_VAR) { - return T(node->u.var).var.ptr_ptr; - } else { - return NULL; - } -} -/* }}} */ - -/* {{{ spl_unlock_zval_ptr_ptr */ -void spl_unlock_zval_ptr_ptr(znode *node, temp_variable *Ts TSRMLS_DC) -{ - if (node->op_type==IS_VAR) { - if (T(node->u.var).var.ptr_ptr) { - spl_pzval_unlock_func(*T(node->u.var).var.ptr_ptr TSRMLS_CC); - } else if (T(node->u.var).EA.type==IS_STRING_OFFSET) { - spl_pzval_unlock_func(T(node->u.var).EA.data.str_offset.str TSRMLS_CC); - } - } -} -/* }}} */ - -/* {{{ spl_get_zval_ptr */ -zval * spl_get_zval_ptr(znode *node, temp_variable *Ts, zval **should_free TSRMLS_DC) -{ - switch (node->op_type) { - case IS_CONST: - *should_free = 0; - return &node->u.constant; - break; - case IS_TMP_VAR: - return *should_free = &T(node->u.var).tmp_var; - break; - case IS_VAR: - if (T(node->u.var).var.ptr) { - spl_pzval_unlock_func(T(node->u.var).var.ptr TSRMLS_CC); - *should_free = 0; - return T(node->u.var).var.ptr; - } else { - *should_free = &T(node->u.var).tmp_var; - - switch (T(node->u.var).EA.type) { - case IS_STRING_OFFSET: { - temp_variable *T = &T(node->u.var); - zval *str = T->EA.data.str_offset.str; - - if (T->EA.data.str_offset.str->type != IS_STRING - || (T->EA.data.str_offset.offset<0) - || (T->EA.data.str_offset.str->value.str.len <= T->EA.data.str_offset.offset)) { - zend_error(E_NOTICE, "Uninitialized string offset: %d", T->EA.data.str_offset.offset); - T->tmp_var.value.str.val = empty_string; - T->tmp_var.value.str.len = 0; - } else { - char c = str->value.str.val[T->EA.data.str_offset.offset]; - - T->tmp_var.value.str.val = estrndup(&c, 1); - T->tmp_var.value.str.len = 1; - } - spl_pzval_unlock_func(str TSRMLS_CC); - T->tmp_var.refcount=1; - T->tmp_var.is_ref=1; - T->tmp_var.type = IS_STRING; - return &T->tmp_var; - } - break; - } - } - break; - case IS_UNUSED: - *should_free = 0; - return NULL; - break; - EMPTY_SWITCH_DEFAULT_CASE() - } - return NULL; -} -/* }}} */ - -/* {{{ spl_is_instance_of */ -int spl_is_instance_of(zval **obj, zend_class_entry *ce TSRMLS_DC) -{ - /* Ensure everything needed is available before checking for the type. - */ - zend_class_entry *instance_ce; - - if (obj && (instance_ce = spl_get_class_entry(*obj TSRMLS_CC)) != NULL) { - return instanceof_function(instance_ce, ce TSRMLS_CC); - } - return 0; -} -/* }}} */ - -/* {{{ spl_implements */ -spl_is_a spl_implements(zend_class_entry *ce) -{ - register spl_is_a is_a = 0; - register int i = ce->num_interfaces; - register zend_class_entry **pce = ce->interfaces; - - while (i--) { - if (*pce == spl_ce_iterator) is_a |= SPL_IS_A_ITERATOR; - else if (*pce == spl_ce_forward) is_a |= SPL_IS_A_FORWARD; - else if (*pce == spl_ce_assoc) is_a |= SPL_IS_A_ASSOC; - else if (*pce == spl_ce_sequence) is_a |= SPL_IS_A_SEQUENCE; - else if (*pce == spl_ce_array_read) is_a |= SPL_IS_A_ARRAY_READ; - else if (*pce == spl_ce_array_access) is_a |= SPL_IS_A_ARRAY_ACCESS; - pce++; - } - return is_a; -} -/* }}} */ - -/* {{{ spl_call_method */ -zval * spl_call_method(zval **object_pp, zend_class_entry *obj_ce, zend_function **fn_proxy, char *function_name, int function_name_len, zval **retval_ptr, int param_count, zval* arg1, zval* arg2 TSRMLS_DC) -{ - int result; - zend_fcall_info fci; - zval z_fname; - zval *retval; - - zval **params[2]; - - params[0] = &arg1; - params[1] = &arg2; - - fci.size = sizeof(fci); - /*fci.function_table = NULL; will be read form zend_class_entry of object if needed */ - fci.object_pp = object_pp; - fci.function_name = &z_fname; - fci.retval_ptr_ptr = retval_ptr ? retval_ptr : &retval; - fci.param_count = param_count; - fci.params = params; - fci.no_separation = 1; - fci.symbol_table = NULL; - - if (!fn_proxy && !obj_ce) { - /* no interest in caching and no information already present that is - * needed later inside zend_call_function. */ - ZVAL_STRINGL(&z_fname, function_name, function_name_len, 0); - result = zend_call_function(&fci, NULL TSRMLS_CC); - } else { - zend_fcall_info_cache fcic; - - fcic.initialized = 1; - if (!obj_ce) { - obj_ce = Z_OBJCE_PP(object_pp); - } - if (!fn_proxy || !*fn_proxy) { - if (zend_hash_find(&obj_ce->function_table, function_name, function_name_len+1, (void **) &fcic.function_handler) == FAILURE) { - /* error at c-level */ - zend_error(E_CORE_ERROR, "Couldn't find implementation for method %s::%s\n", obj_ce->name, function_name); - } - if (fn_proxy) { - *fn_proxy = fcic.function_handler; - } - } else { - fcic.function_handler = *fn_proxy; - } - fcic.calling_scope = obj_ce; - fcic.object_pp = object_pp; - result = zend_call_function(&fci, &fcic TSRMLS_CC); - } - if (result == FAILURE) { - /* error at c-level */ - if (!obj_ce) { - obj_ce = Z_OBJCE_PP(object_pp); - } - zend_error(E_CORE_ERROR, "Couldn't execute method %s::%s\n", obj_ce->name, function_name); - } - if (!retval_ptr && retval) { - zval_dtor(retval); - FREE_ZVAL(retval); - return NULL; - } - return *retval_ptr; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl_engine.h b/ext/spl/spl_engine.h deleted file mode 100755 index 19f4ccc83b..0000000000 --- a/ext/spl/spl_engine.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -#ifndef SPL_ENGINE_H -#define SPL_ENGINE_H - -#include "php.h" -#include "php_spl.h" - -#include "zend_compile.h" - -#undef EX -#define EX(element) execute_data->element -#define EX_T(offset) (*(temp_variable *)((char *) EX(Ts) + offset)) -#define T(offset) (*(temp_variable *)((char *) Ts + offset)) - -#define NEXT_OPCODE() \ - EX(opline)++; \ - return 0; - -zval * spl_call_method(zval **object_pp, zend_class_entry *obj_ce, zend_function **fn_proxy, char *function_name, int function_name_len, zval **retval_ptr, int param_count, zval* arg1, zval* arg2 TSRMLS_DC); - -/* {{{ zend_class_entry */ -static inline zend_class_entry *spl_get_class_entry(zval *obj TSRMLS_DC) -{ - if (obj && Z_TYPE_P(obj) == IS_OBJECT && Z_OBJ_HT_P(obj)->get_class_entry) { - return Z_OBJ_HT_P(obj)->get_class_entry(obj TSRMLS_CC); - } else { - return NULL; - } -} -/* }}} */ - -#define spl_call_method_0(obj, obj_ce, fn_proxy, function_name, fname_len, retval) \ - spl_call_method(obj, obj_ce, fn_proxy, function_name, fname_len, retval, 0, NULL, NULL TSRMLS_CC) - -#define spl_call_method_1(obj, obj_ce, fn_proxy, function_name, fname_len, retval, arg1) \ - spl_call_method(obj, obj_ce, fn_proxy, function_name, fname_len, retval, 1, arg1, NULL TSRMLS_CC) - -#define spl_call_method_2(obj, obj_ce, fn_proxy, function_name, fname_len, retval, arg1, arg2) \ - spl_call_method(obj, obj_ce, fn_proxy, function_name, fname_len, retval, 2, arg1, arg2 TSRMLS_CC) - -void spl_instanciate(zend_class_entry *pce, zval **object TSRMLS_DC); -int spl_instanciate_arg_ex2(zend_class_entry *pce, zval **retval, zval *arg1, zval *arg2 TSRMLS_DC); - -zval ** spl_get_zval_ptr_ptr(znode *node, temp_variable *Ts TSRMLS_DC); -void spl_unlock_zval_ptr_ptr(znode *node, temp_variable *Ts TSRMLS_DC); -zval * spl_get_zval_ptr(znode *node, temp_variable *Ts, zval **should_free TSRMLS_DC); - -int spl_is_instance_of(zval **obj, zend_class_entry *ce TSRMLS_DC); - -typedef enum { - SPL_IS_A_ITERATOR = 0x01, - SPL_IS_A_FORWARD = 0x02, - SPL_IS_A_ASSOC = 0x04, - SPL_IS_A_SEQUENCE = 0x08, - SPL_IS_A_ARRAY_READ = 0x10, - SPL_IS_A_ARRAY_ACCESS = 0x20 -} spl_is_a; - -spl_is_a spl_implements(zend_class_entry *ce); - -/* Use this only insode OPCODE-Hooks */ -static inline void spl_pzval_unlock_func(zval *z TSRMLS_DC) -{ - z->refcount--; - if (!z->refcount) { - z->refcount = 1; - z->is_ref = 0; - EG(garbage)[EG(garbage_ptr)++] = z; - } -} - -/* Use this only insode OPCODE-Hooks */ -static inline void spl_pzval_lock_func(zval *z) -{ - z->refcount++; -} - -/* Use this only insode OPCODE-Hooks */ -#define SELECTIVE_PZVAL_LOCK(pzv, pzn) if (!((pzn)->u.EA.type & EXT_TYPE_UNUSED)) { spl_pzval_lock_func(pzv); } - -#endif /* SPL_ENGINE_H */ - -/* - * Local Variables: - * c-basic-offset: 4 - * tab-width: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl_foreach.c b/ext/spl/spl_foreach.c deleted file mode 100755 index 90441415d8..0000000000 --- a/ext/spl/spl_foreach.c +++ /dev/null @@ -1,269 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" -#include "zend_compile.h" - -#include "php_spl.h" -#include "spl_functions.h" -#include "spl_engine.h" -#include "spl_foreach.h" - -#define OPTIMIZED_ARRAY_CONSTRUCT - -typedef struct { - zend_function *next; - zend_function *rewind; - zend_function *more; - zend_function *current; - zend_function *key; -} spl_foreach_funcs; - -typedef struct { - zval *obj; - zend_class_entry *obj_ce; - zend_uint index; - spl_is_a is_a; - spl_foreach_funcs funcs; - char dummy; /* needed for '\0' but we can't set it due to compiler optimizations */ -} spl_foreach_proxy; - -/* {{{ ZEND_EXECUTE_HOOK_FUNCTION(ZEND_FE_RESET) */ -ZEND_EXECUTE_HOOK_FUNCTION(ZEND_FE_RESET) -{ - zval **obj, *retval; - spl_foreach_proxy *proxy; - zend_class_entry *instance_ce, *obj_ce; - spl_is_a is_a; - temp_variable *tmp; - - obj = spl_get_zval_ptr_ptr(&EX(opline)->op1, EX(Ts) TSRMLS_CC); - - if (!obj || (instance_ce = spl_get_class_entry(*obj TSRMLS_CC)) == NULL) { - ZEND_EXECUTE_HOOK_ORIGINAL(ZEND_FE_RESET); - } - - is_a = spl_implements(instance_ce); - - if (is_a & SPL_IS_A_ITERATOR) { - spl_unlock_zval_ptr_ptr(&EX(opline)->op1, EX(Ts) TSRMLS_CC); - obj_ce = instance_ce; - spl_call_method_0(obj, obj_ce, NULL, "newiterator", sizeof("newiterator")-1, &retval); - instance_ce = spl_get_class_entry(retval TSRMLS_CC); - is_a = spl_implements(instance_ce); - if (!(is_a & SPL_IS_A_FORWARD)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Objects created by %s::newIterator() must implement spl_forward", obj_ce->name); - ZEND_EXECUTE_HOOK_ORIGINAL(ZEND_FE_RESET); - } - spl_pzval_lock_func(retval); - } else if (is_a & SPL_IS_A_FORWARD) { - spl_unlock_zval_ptr_ptr(&EX(opline)->op1, EX(Ts) TSRMLS_CC); - retval = *obj; - retval->refcount += 2; /* lock two times */ - } else { - ZEND_EXECUTE_HOOK_ORIGINAL(ZEND_FE_RESET); - } - - /* create the proxy */ - proxy = emalloc(sizeof(spl_foreach_proxy)); - proxy->obj = retval; - proxy->obj_ce = instance_ce; - proxy->index = 0; - proxy->is_a = is_a; - memset(&proxy->funcs, 0, sizeof(spl_foreach_funcs)); - ((char*)proxy)[sizeof(spl_foreach_proxy)-1] = '\0'; - /* And pack it into a zval. Since it is nowhere accessible using a - * zval of type STRING is the fastest approach of storing the proxy. - */ - ALLOC_ZVAL(retval); - ZVAL_STRINGL(retval, (char*)proxy, sizeof(spl_foreach_proxy)-1, 0); - retval->is_ref = 0; - retval->refcount = 2; /* lock two times */ - /* return the created proxy container */ - tmp = &EX_T(EX(opline)->result.u.var); - tmp->var.ptr = retval; - tmp->var.ptr_ptr = &tmp->var.ptr; - - NEXT_OPCODE(); -} -/* }}} */ - -/* {{{ OPTIMIZED_ARRAY_CONSTRUCT macros */ -#ifdef OPTIMIZED_ARRAY_CONSTRUCT -#define CONNECT_TO_BUCKET_DLLIST(element, list_head) \ - (element)->pNext = (list_head); \ - (element)->pLast = NULL; - -#define CONNECT_TO_GLOBAL_DLLIST(element, ht) \ - (element)->pListLast = (ht)->pListTail; \ - (ht)->pListTail = (element); \ - (element)->pListNext = NULL; \ - if ((element)->pListLast != NULL) { \ - (element)->pListLast->pListNext = (element); \ - } \ - if (!(ht)->pListHead) { \ - (ht)->pListHead = (element); \ - } \ - if ((ht)->pInternalPointer == NULL) { \ - (ht)->pInternalPointer = (element); \ - } -#endif -/* }}} */ - -/* {{{ ZEND_EXECUTE_HOOK_FUNCTION(ZEND_FE_FETCH) */ -ZEND_EXECUTE_HOOK_FUNCTION(ZEND_FE_FETCH) -{ - znode *op1 = &EX(opline)->op1; - zval **obj = spl_get_zval_ptr_ptr(op1, EX(Ts) TSRMLS_CC); - zval *more, *value, *key, *result; - spl_foreach_proxy *proxy; - - if (Z_TYPE_PP(obj) == IS_STRING) { - int has_more; - - proxy = (spl_foreach_proxy*)Z_STRVAL_PP(obj); - obj = &proxy->obj; /* will be optimized out */ - - if (proxy->index++) { - spl_call_method_0(obj, proxy->obj_ce, &proxy->funcs.next, "next", sizeof("next")-1, NULL); - } else { - if (proxy->is_a & SPL_IS_A_SEQUENCE) { - spl_call_method_0(obj, proxy->obj_ce, &proxy->funcs.rewind, "rewind", sizeof("rewind")-1, NULL); - } - /* now this is an optimization trick: - ZEND_SWITCH_FREE receives the array copy or the spl object in op1 and has an unused op2 - We have to check for op1 being an object that implements spl_forwar... Or we simply set - op2 and know we can safely free the object as needed, which is waht we do. */ - op_array->opcodes[EX(opline)->op2.u.opline_num].op2 = *op1; - } - - spl_call_method_0(obj, proxy->obj_ce, &proxy->funcs.more, "hasmore", sizeof("hasmore")-1, &more); - has_more = i_zend_is_true(more); - zval_dtor(more); - FREE_ZVAL(more); - if (has_more) { - result = &EX_T(EX(opline)->result.u.var).tmp_var; - - spl_call_method_0(obj, proxy->obj_ce, &proxy->funcs.current, "current", sizeof("current")-1, &value); - - if (proxy->is_a & SPL_IS_A_ASSOC) { - spl_call_method_0(obj, proxy->obj_ce, &proxy->funcs.key, "key", sizeof("key")-1, &key); - } else { - MAKE_STD_ZVAL(key); - key->value.lval = proxy->index; - key->type = IS_LONG; - } -#ifndef OPTIMIZED_ARRAY_CONSTRUCT - array_init(result); - add_next_index_zval(result, value); - add_next_index_zval(result, key); -#else - { - Bucket *p; - HashTable *ht; - - ht = emalloc(sizeof(HashTable)); - result->value.ht = ht; - ht->nTableSize = 1 << 1; - ht->nTableMask = ht->nTableSize - 1; -#if ZEND_DEBUG - ht->inconsistent = 0; /*HT_OK;*/ -#endif - - ht->arBuckets = (Bucket **)emalloc(ht->nTableSize * sizeof(Bucket *)); - - ht->pDestructor = ZVAL_PTR_DTOR; - ht->pListHead = NULL; - ht->pListTail = NULL; - ht->nNumOfElements = 0; - ht->nNextFreeElement = 0; - ht->pInternalPointer = NULL; - ht->persistent = 0; - ht->nApplyCount = 0; - ht->bApplyProtection = 1; - result->type = IS_ARRAY; - - p = (Bucket*)emalloc(sizeof(Bucket)-1); - p->pDataPtr = value; - p->pData = &p->pDataPtr; - p->nKeyLength = 0; - p->h = 0; - result->value.ht->arBuckets[0] = p; - CONNECT_TO_BUCKET_DLLIST(p, ht->arBuckets[0]); - CONNECT_TO_GLOBAL_DLLIST(p, ht); - - p = (Bucket*)emalloc(sizeof(Bucket)-1); - p->pDataPtr = key; - p->pData = &p->pDataPtr; - p->nKeyLength = 0; - p->h = 1; - result->value.ht->arBuckets[1] = p; - CONNECT_TO_BUCKET_DLLIST(p, ht->arBuckets[1]); - CONNECT_TO_GLOBAL_DLLIST(p, ht); - - ht->nNumOfElements = 2; - } -#endif - NEXT_OPCODE(); - } - EX(opline) = op_array->opcodes+EX(opline)->op2.u.opline_num; - return 0; - } - ZEND_EXECUTE_HOOK_ORIGINAL(ZEND_FE_FETCH); -} -/* }}} */ - -/* {{{ ZEND_EXECUTE_HOOK_FUNCTION(ZEND_SWITCH_FREE) */ -ZEND_EXECUTE_HOOK_FUNCTION(ZEND_SWITCH_FREE) -{ - /* See not in ZEND_FE_FETCH on setting op2 */ - znode *op2 = &EX(opline)->op2; - zval *tmp, **obj = spl_get_zval_ptr_ptr(op2, EX(Ts) TSRMLS_CC); - spl_foreach_proxy *proxy; - - if (obj) { - proxy = (spl_foreach_proxy*)Z_STRVAL_PP(obj); - tmp = *obj; - *obj = proxy->obj; /* restore */ - - efree(tmp->value.str.val); - FREE_ZVAL(tmp); - - spl_unlock_zval_ptr_ptr(&EX(opline)->op1, EX(Ts) TSRMLS_CC); - spl_pzval_lock_func(*obj); - - SET_UNUSED(*op2); - } - ZEND_EXECUTE_HOOK_ORIGINAL(ZEND_SWITCH_FREE); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl_foreach.h b/ext/spl/spl_foreach.h deleted file mode 100755 index e27f9e77de..0000000000 --- a/ext/spl/spl_foreach.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -#ifndef SPL_FOREACH_H -#define SPL_FOREACH_H - -#include "php.h" -#include "php_spl.h" - -ZEND_EXECUTE_HOOK_FUNCTION(ZEND_FE_RESET); -ZEND_EXECUTE_HOOK_FUNCTION(ZEND_FE_FETCH); -ZEND_EXECUTE_HOOK_FUNCTION(ZEND_SWITCH_FREE); - -#endif /* SPL_FOREACH_H */ - -/* - * Local Variables: - * c-basic-offset: 4 - * tab-width: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl_functions.c b/ext/spl/spl_functions.c deleted file mode 100755 index 126a6f15e3..0000000000 --- a/ext/spl/spl_functions.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" -#include "php_spl.h" -#include "spl_foreach.h" - -/* {{{ spl_destroy_class */ -void spl_destroy_class(zend_class_entry ** ppce) -{ - SPL_DEBUG(fprintf(stderr, "Destroy(%s): %s\n", (*ppce)->type == ZEND_USER_CLASS ? "user" : "other", (*ppce)->name);) - destroy_zend_class(ppce); -} -/* }}} */ - -/* {{{ spl_register_interface */ -void spl_register_interface(zend_class_entry ** ppce, char * class_name, zend_function_entry *functions TSRMLS_DC) -{ - zend_class_entry ce; - - INIT_CLASS_ENTRY(ce, class_name, functions); - ce.name_length = strlen(class_name); - *ppce = zend_register_internal_class(&ce TSRMLS_CC); - - /* entries changed by initialize */ - (*ppce)->ce_flags = ZEND_ACC_ABSTRACT | ZEND_ACC_INTERFACE; -} -/* }}} */ - -/* {{{ spl_register_std_class */ -void spl_register_std_class(zend_class_entry ** ppce, char * class_name, void * obj_ctor, function_entry * function_list TSRMLS_DC) -{ - zend_class_entry ce; - - INIT_CLASS_ENTRY(ce, class_name, function_list); - ce.name_length = strlen(class_name); - *ppce = zend_register_internal_class(&ce TSRMLS_CC); - - /* entries changed by initialize */ - (*ppce)->create_object = obj_ctor; -} -/* }}} */ - -/* {{{ spl_register_parent_ce */ -void spl_register_parent_ce(zend_class_entry * class_entry, zend_class_entry * parent_class TSRMLS_DC) -{ - class_entry->parent = parent_class; -} -/* }}} */ - -/* {{{ spl_register_implement */ -void spl_register_implement(zend_class_entry * class_entry, zend_class_entry * interface_entry TSRMLS_DC) -{ - zend_class_implements(class_entry TSRMLS_CC, 1, interface_entry); -} -/* }}} */ - -/* {{{ spl_register_functions */ -void spl_register_functions(zend_class_entry * class_entry, function_entry * function_list TSRMLS_DC) -{ - zend_register_functions(class_entry, function_list, &class_entry->function_table, MODULE_PERSISTENT TSRMLS_CC); -} -/* }}} */ - -/* {{{ spl_register_property */ -void spl_register_property( zend_class_entry * class_entry, char *prop_name, zval *prop_val, int prop_flags TSRMLS_DC) -{ - if (!prop_val) { - INIT_PZVAL(prop_val); - prop_val->type = IS_NULL; - } - - zend_declare_property(class_entry, prop_name, strlen(prop_name), prop_val, prop_flags TSRMLS_CC); -} -/* }}} */ - -/* {{{ spl_add_class_name */ -void spl_add_class_name(zval * list, zend_class_entry * pce TSRMLS_DC) -{ - size_t len = strlen(pce->name); - zval *tmp; - - if (zend_hash_find(Z_ARRVAL_P(list), pce->name, len+1, (void*)&tmp) == FAILURE) { - MAKE_STD_ZVAL(tmp); - ZVAL_STRING(tmp, pce->name, 1); - zend_hash_add(Z_ARRVAL_P(list), pce->name, len+1, &tmp, sizeof(zval *), NULL); - } -} -/* }}} */ - -/* {{{ spl_add_interfaces */ -void spl_add_interfaces(zval *list, zend_class_entry * pce TSRMLS_DC) -{ - zend_uint num_interfaces; - - for (num_interfaces = 0; num_interfaces < pce->num_interfaces; num_interfaces++) { - spl_add_class_name(list, pce->interfaces[num_interfaces] TSRMLS_CC); - } -} -/* }}} */ - -/* {{{ spl_add_classes */ -int spl_add_classes(zend_class_entry ** ppce, zval *list TSRMLS_DC) -{ - zend_class_entry *pce = *ppce; - spl_add_class_name(list, pce TSRMLS_CC); - spl_add_interfaces(list, pce TSRMLS_CC); - while (pce->parent) { - pce = pce->parent; - spl_add_classes(&pce, list TSRMLS_CC); - } - return 0; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl_functions.h b/ext/spl/spl_functions.h deleted file mode 100755 index 1a2aa15037..0000000000 --- a/ext/spl/spl_functions.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -#ifndef PHP_FUNCTIONS_H -#define PHP_FUNCTIONS_H - -#include "php.h" - -typedef zend_object_value (*create_object_func_t)(zend_class_entry *class_type TSRMLS_DC); - -#define REGISTER_SPL_STD_CLASS(class_name, obj_ctor) \ - spl_register_std_class(&spl_ce_ ## class_name, "spl_" # class_name, obj_ctor, NULL TSRMLS_CC); - -#define REGISTER_SPL_STD_CLASS_EX(class_name, obj_ctor, funcs) \ - spl_register_std_class(&spl_ce_ ## class_name, "spl_" # class_name, obj_ctor, funcs TSRMLS_CC); - -#define REGISTER_SPL_INTERFACE(class_name) \ - spl_register_interface(&spl_ce_ ## class_name, "spl_" # class_name, spl_funcs_ ## class_name TSRMLS_CC); - -#define REGISTER_SPL_PARENT_CE(class_name, parent_class) \ - spl_register_parent_ce(spl_ce_ ## class_name, spl_ce_ ## parent_class TSRMLS_CC); - -#define REGISTER_SPL_IMPLEMENT(class_name, interface_name) \ - spl_register_implement(spl_ce_ ## class_name, spl_ce_ ## interface_name TSRMLS_CC); - -#define REGISTER_SPL_FUNCTIONS(class_name, function_list) \ - spl_register_functions(spl_ce_ ## class_name, function_list TSRMLS_CC); - -#define REGISTER_SPL_PROPERTY(class_name, prop_name) \ - spl_register_property(spl_ce_ ## class_name, prop_name, prop_val, prop_flags TSRMLS_CC); - -void spl_destroy_class(zend_class_entry ** ppce); - -void spl_register_std_class(zend_class_entry ** ppce, char * class_name, create_object_func_t ctor, function_entry * function_list TSRMLS_DC); - -void spl_register_interface(zend_class_entry ** ppce, char * class_name, zend_function_entry *functions TSRMLS_DC); - -void spl_register_parent_ce(zend_class_entry * class_entry, zend_class_entry * parent_class TSRMLS_DC); -void spl_register_implement(zend_class_entry * class_entry, zend_class_entry * interface_entry TSRMLS_DC); -void spl_register_functions(zend_class_entry * class_entry, function_entry * function_list TSRMLS_DC); -void spl_register_property( zend_class_entry * class_entry, char *prop_name, zval *prop_val, int prop_flags TSRMLS_DC); - -void spl_add_class_name(zval * list, zend_class_entry * pce TSRMLS_DC); -void spl_add_interfaces(zval * list, zend_class_entry * pce TSRMLS_DC); -int spl_add_classes(zend_class_entry ** ppce, zval *list TSRMLS_DC); - -#define SPL_CLASS_FE(class_name, function_name, arg_info, flags) \ - PHP_ME( spl_ ## class_name, function_name, arg_info, flags) - -#define SPL_CLASS_FUNCTION(class_name, function_name) \ - PHP_METHOD(spl_ ## class_name, function_name) - -#endif /* PHP_FUNCTIONS_H */ - -/* - * Local Variables: - * c-basic-offset: 4 - * tab-width: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/tests/.htaccess b/ext/spl/tests/.htaccess deleted file mode 100755 index 5a01a1c16e..0000000000 --- a/ext/spl/tests/.htaccess +++ /dev/null @@ -1,3 +0,0 @@ -<IfModule mod_autoindex.c> - IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t *.php -</IfModule> diff --git a/ext/spl/tests/array.phpt b/ext/spl/tests/array.phpt deleted file mode 100755 index 1474564dc0..0000000000 --- a/ext/spl/tests/array.phpt +++ /dev/null @@ -1,88 +0,0 @@ ---TEST-- -SPL: array ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$ar = array(0=>0, 1=>1); -$ar = new spl_array($ar); - -var_dump($ar); - -$ar[2] = 2; -var_dump($ar[2]); -var_dump($ar["3"] = 3); - -var_dump(array_merge((array)$ar, array(4=>4, 5=>5))); - -var_dump($ar["a"] = "a"); - -var_dump($ar); -var_dump($ar[0]); -var_dump($ar[6]); -var_dump($ar["b"]); - -unset($ar[1]); -unset($ar["3"]); -unset($ar["a"]); -unset($ar[7]); -unset($ar["c"]); -var_dump($ar); - -echo "Done\n"; -?> ---EXPECTF-- -object(spl_array)#1 (2) { - [0]=> - int(0) - [1]=> - int(1) -} -int(2) -int(3) -array(6) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - &int(2) - [3]=> - &int(3) - [4]=> - int(4) - [5]=> - int(5) -} -string(1) "a" -object(spl_array)#1 (5) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - &int(2) - [3]=> - &int(3) - ["a"]=> - &string(1) "a" -} -int(0) - -Notice: Undefined offset: 6 in %sarray.php on line %d -NULL - -Notice: Undefined index: b in %sarray.php on line %d -NULL - -Notice: Undefined offset: 7 in %sarray.php on line %d - -Notice: Undefined index: c in %sarray.php on line %d -object(spl_array)#1 (2) { - [0]=> - int(0) - [2]=> - &int(2) -} -Done diff --git a/ext/spl/tests/array_access_001.phpt b/ext/spl/tests/array_access_001.phpt deleted file mode 100755 index 2292749db2..0000000000 --- a/ext/spl/tests/array_access_001.phpt +++ /dev/null @@ -1,163 +0,0 @@ ---TEST-- -SPL: array_access ---SKIPIF-- -<?php - if (!extension_loaded("spl")) die("skip"); - if (!in_array("spl_array_access", spl_classes())) die("skip spl_array_access not present"); -?> ---FILE-- -<?php -class c implements spl_array_access { - - public $a = array('1st', 1, 2=>'3rd', '4th'=>4); - function exists($index) { - echo __METHOD__ . "($index)\n"; - return array_key_exists($index, $this->a); - } - function get($index) { - echo __METHOD__ . "($index)\n"; - return $this->a[$index]; - } - function set($index, $newval) { - echo __METHOD__ . "($index,$newval)\n"; - return $this->a[$index] = $newval; - } - function del($index) { - echo __METHOD__ . "($index)\n"; - unset($this->a[$index]); - } -} - -$obj = new c(); - -var_dump($obj->a); - -var_dump($obj[0]); -var_dump($obj[1]); -var_dump($obj[2]); -var_dump($obj['4th']); -var_dump($obj['5th']); -var_dump($obj[6]); - -echo "WRITE 1\n"; -$obj[1] = 'Changed 1'; -var_dump($obj[1]); -echo "WRITE 2\n"; -$obj['4th'] = 'Changed 4th'; -var_dump($obj['4th']); -echo "WRITE 3\n"; -$obj['5th'] = 'Added 5th'; -var_dump($obj['5th']); -echo "WRITE 4\n"; -$obj[6] = 'Added 6'; -var_dump($obj[6]); - -var_dump($obj[0]); -var_dump($obj[2]); - -$x = $obj[6] = 'changed 6'; -var_dump($obj[6]); -var_dump($x); - -echo "===unset===\n"; -var_dump($obj->a); -unset($obj[2]); -unset($obj['4th']); -unset($obj[7]); -unset($obj['8th']); -var_dump($obj->a); - -print "Done\n"; -?> ---EXPECTF-- -array(4) { - [0]=> - string(3) "1st" - [1]=> - int(1) - [2]=> - string(3) "3rd" - ["4th"]=> - int(4) -} -c::exists(0) -c::get(0) -string(3) "1st" -c::exists(1) -c::get(1) -int(1) -c::exists(2) -c::get(2) -string(3) "3rd" -c::exists(4th) -c::get(4th) -int(4) -c::exists(5th) - -Notice: Undefined index: 5th in %sarray_access_001.php on line %d -NULL -c::exists(6) - -Notice: Undefined index: 6 in %sarray_access_001.php on line %d -NULL -WRITE 1 -c::set(1,Changed 1) -c::exists(1) -c::get(1) -string(9) "Changed 1" -WRITE 2 -c::set(4th,Changed 4th) -c::exists(4th) -c::get(4th) -string(11) "Changed 4th" -WRITE 3 -c::set(5th,Added 5th) -c::exists(5th) -c::get(5th) -string(9) "Added 5th" -WRITE 4 -c::set(6,Added 6) -c::exists(6) -c::get(6) -string(7) "Added 6" -c::exists(0) -c::get(0) -string(3) "1st" -c::exists(2) -c::get(2) -string(3) "3rd" -c::set(6,changed 6) -c::exists(6) -c::get(6) -string(9) "changed 6" -string(9) "changed 6" -===unset=== -array(6) { - [0]=> - string(3) "1st" - [1]=> - string(9) "Changed 1" - [2]=> - string(3) "3rd" - ["4th"]=> - string(11) "Changed 4th" - ["5th"]=> - string(9) "Added 5th" - [6]=> - string(9) "changed 6" -} -c::del(2) -c::del(4th) -c::del(7) -c::del(8th) -array(4) { - [0]=> - string(3) "1st" - [1]=> - string(9) "Changed 1" - ["5th"]=> - string(9) "Added 5th" - [6]=> - string(9) "changed 6" -} -Done diff --git a/ext/spl/tests/array_access_002.phpt b/ext/spl/tests/array_access_002.phpt deleted file mode 100755 index 133e6f3f4a..0000000000 --- a/ext/spl/tests/array_access_002.phpt +++ /dev/null @@ -1,137 +0,0 @@ ---TEST-- -SPL: array_access without return in set() ---SKIPIF-- -<?php - if (!extension_loaded("spl")) die("skip"); - if (!in_array("spl_array_access", spl_classes())) die("skip spl_array_access not present"); -?> ---FILE-- -<?php -class c implements spl_array_access { - - public $a = array('1st', 1, 2=>'3rd', '4th'=>4); - - function exists($index) { - echo __METHOD__ . "($index)\n"; - return array_key_exists($index, $this->a); - } - function get($index) { - echo __METHOD__ . "($index)\n"; - return $this->a[$index]; - } - function set($index, $newval) { - echo __METHOD__ . "($index,$newval)\n"; - /* return */ $this->a[$index] = $newval; - } - function del($index) { - echo __METHOD__ . "($index)\n"; - unset($this->a[$index]); - } -} - -$obj = new c(); - -var_dump($obj->a); - -var_dump($obj[0]); -var_dump($obj[1]); -var_dump($obj[2]); -var_dump($obj['4th']); -var_dump($obj['5th']); -var_dump($obj[6]); - -echo "WRITE 1\n"; -$obj[1] = 'Changed 1'; -var_dump($obj[1]); -echo "WRITE 2\n"; -$obj['4th'] = 'Changed 4th'; -var_dump($obj['4th']); -echo "WRITE 3\n"; -$obj['5th'] = 'Added 5th'; -var_dump($obj['5th']); -echo "WRITE 4\n"; -$obj[6] = 'Added 6'; -var_dump($obj[6]); - -var_dump($obj[0]); -var_dump($obj[2]); - -$x = $obj[6] = 'changed 6'; -var_dump($obj[6]); -var_dump($x); - -print "Done\n"; -?> ---EXPECTF-- -array(4) { - [0]=> - string(3) "1st" - [1]=> - int(1) - [2]=> - string(3) "3rd" - ["4th"]=> - int(4) -} -c::exists(0) -c::get(0) -string(3) "1st" -c::exists(1) -c::get(1) -int(1) -c::exists(2) -c::get(2) -string(3) "3rd" -c::exists(4th) -c::get(4th) -int(4) -c::exists(5th) - -Notice: Undefined index: 5th in %sarray_access_002.php on line %d -NULL -c::exists(6) - -Notice: Undefined index: 6 in %sarray_access_002.php on line %d -NULL -WRITE 1 -c::set(1,Changed 1) - -Warning: Method c::set() did not return a value, using input value in %sarray_access_002.php on line %d -c::exists(1) -c::get(1) -string(9) "Changed 1" -WRITE 2 -c::set(4th,Changed 4th) - -Warning: Method c::set() did not return a value, using input value in %sarray_access_002.php on line %d -c::exists(4th) -c::get(4th) -string(11) "Changed 4th" -WRITE 3 -c::set(5th,Added 5th) - -Warning: Method c::set() did not return a value, using input value in %sarray_access_002.php on line %d -c::exists(5th) -c::get(5th) -string(9) "Added 5th" -WRITE 4 -c::set(6,Added 6) - -Warning: Method c::set() did not return a value, using input value in %sarray_access_002.php on line %d -c::exists(6) -c::get(6) -string(7) "Added 6" -c::exists(0) -c::get(0) -string(3) "1st" -c::exists(2) -c::get(2) -string(3) "3rd" -c::set(6,changed 6) - -Warning: Method c::set() did not return a value, using input value in %sarray_access_002.php on line %d -c::exists(6) -c::get(6) -string(9) "changed 6" -string(9) "changed 6" -Done diff --git a/ext/spl/tests/array_iterator.phpt b/ext/spl/tests/array_iterator.phpt deleted file mode 100755 index 751e623d1c..0000000000 --- a/ext/spl/tests/array_iterator.phpt +++ /dev/null @@ -1,138 +0,0 @@ ---TEST-- -SPL: spl_array_iterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -echo "==Normal==\n"; - -$arr = array(0=>0, 1=>1, 2=>2); -$obj = new spl_array($arr); - -foreach($obj as $ak=>$av) { - foreach($obj as $bk=>$bv) { - if ($ak==0 && $bk==0) { - $arr[0] = "modify"; - } - echo "$ak=>$av - $bk=>$bv\n"; - } -} - -echo "==UseRef==\n"; - -$arr = array(0=>0, 1=>1, 2=>2); -$obj = new spl_array(&$arr); - -foreach($obj as $ak=>$av) { - foreach($obj as $bk=>$bv) { - echo "$ak=>$av - $bk=>$bv\n"; - } -} - -echo "==Modify==\n"; - -$arr = array(0=>0, 1=>1, 2=>2); -$obj = new spl_array(&$arr); - -foreach($obj as $ak=>$av) { - foreach($obj as $bk=>$bv) { - if ($ak==0 && $bk==0) { - $arr[0] = "modify"; - } - echo "$ak=>$av - $bk=>$bv\n"; - } -} - -echo "==Delete==\n"; - -$arr = array(0=>0, 1=>1, 2=>2); -$obj = new spl_array(&$arr); - -foreach($obj as $ak=>$av) { - foreach($obj as $bk=>$bv) { - if ($ak==1 && $bk==1) { - unset($arr[1]); - } - echo "$ak=>$av - $bk=>$bv\n"; - } -} - -echo "==Change==\n"; - -$arr = array(0=>0, 1=>1, 2=>2); -$obj = new spl_array(&$arr); - -foreach($obj as $ak=>$av) { - foreach($obj as $bk=>$bv) { - if ($ak==1 && $bk==1) { - $arr = NULL; - } - echo "$ak=>$av - $bk=>$bv\n"; - } -} - -echo "Done\n"; -?> ---EXPECTF-- -==Normal== -0=>0 - 0=>0 -0=>0 - 1=>1 -0=>0 - 2=>2 -1=>1 - 0=>0 -1=>1 - 1=>1 -1=>1 - 2=>2 -2=>2 - 0=>0 -2=>2 - 1=>1 -2=>2 - 2=>2 -==UseRef== -0=>0 - 0=>0 -0=>0 - 1=>1 -0=>0 - 2=>2 -1=>1 - 0=>0 -1=>1 - 1=>1 -1=>1 - 2=>2 -2=>2 - 0=>0 -2=>2 - 1=>1 -2=>2 - 2=>2 -==Modify== -0=>0 - 0=>0 -0=>0 - 1=>1 -0=>0 - 2=>2 -1=>1 - 0=>modify -1=>1 - 1=>1 -1=>1 - 2=>2 -2=>2 - 0=>modify -2=>2 - 1=>1 -2=>2 - 2=>2 -==Delete== -0=>0 - 0=>0 -0=>0 - 1=>1 -0=>0 - 2=>2 -1=>1 - 0=>0 -1=>1 - 1=>1 - -Notice: spl_array_it::next(): Array was modified outside object and internal position is no longer valid in %sarray_iterator.php on line %d -1=>1 - 0=>0 -1=>1 - 2=>2 - -Notice: spl_array_it::next(): Array was modified outside object and internal position is no longer valid in %sarray_iterator.php on line %d -0=>0 - 0=>0 -0=>0 - 2=>2 -2=>2 - 0=>0 -2=>2 - 2=>2 -==Change== -0=>0 - 0=>0 -0=>0 - 1=>1 -0=>0 - 2=>2 -1=>1 - 0=>0 -1=>1 - 1=>1 - -Notice: spl_array_it::next(): Array was modified outside object and is no longer an array in %sarray_iterator.php on line %d - -Notice: spl_array_it::hasMore(): Array was modified outside object and is no longer an array in %sarray_iterator.php on line %d - -Notice: spl_array_it::next(): Array was modified outside object and is no longer an array in %sarray_iterator.php on line %d - -Notice: spl_array_it::hasMore(): Array was modified outside object and is no longer an array in %sarray_iterator.php on line %d -Done diff --git a/ext/spl/tests/array_read.phpt b/ext/spl/tests/array_read.phpt deleted file mode 100755 index 032373d52d..0000000000 --- a/ext/spl/tests/array_read.phpt +++ /dev/null @@ -1,208 +0,0 @@ ---TEST-- -SPL: array_read ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -echo "EXTERNAL\n"; - -$a = array('1st', 1, 2=>'3rd', '4th'=>4); -var_dump($a); - -class external implements spl_array_read { - - function exists($index) { - echo __METHOD__ . "($index)\n"; - return array_key_exists($index, $GLOBALS['a']); - } - - function get($index) { - echo __METHOD__ . "($index)\n"; - return $GLOBALS['a'][$index]; - } -} - -$obj = new external(); - -var_dump($obj->get(0)); -var_dump($obj->get(1)); -var_dump($obj->get(2)); -var_dump($obj->get('4th')); -var_dump($obj->get('5th')); -var_dump($obj->get(6)); - -var_dump($obj[0]); -var_dump($obj[1]); -var_dump($obj[2]); -var_dump($obj['4th']); -var_dump($obj['5th']); -var_dump($obj[6]); - -$out = $obj[0]; echo "$out\n"; -$out = $obj[1]; echo "$out\n"; -$out = $obj[2]; echo "$out\n"; -$out = $obj['4th']; echo "$out\n"; - -echo "INTERNAL\n"; - -class internal implements spl_array_read { - - public $a = array('1st', 1, 2=>'3rd', '4th'=>4); - - function exists($index) { - echo __METHOD__ . "($index)\n"; - return array_key_exists($index, $GLOBALS['a']); - } - - function get($index) { - echo __METHOD__ . "($index)\n"; - return $GLOBALS['a'][$index]; - } -} - -$obj = new internal(); - -var_dump($obj->a); - -var_dump($obj->get(0)); -var_dump($obj->get(1)); -var_dump($obj->get(2)); -var_dump($obj->get('4th')); -var_dump($obj->get('5th')); -var_dump($obj->get(6)); - -var_dump($obj[0]); -var_dump($obj[1]); -var_dump($obj[2]); -var_dump($obj['4th']); -var_dump($obj['5th']); -var_dump($obj[6]); - -$out = $obj[0]; echo "$out\n"; -$out = $obj[1]; echo "$out\n"; -$out = $obj[2]; echo "$out\n"; -$out = $obj['4th']; echo "$out\n"; - -print "Done\n"; -?> ---EXPECTF-- -EXTERNAL -array(4) { - [0]=> - string(3) "1st" - [1]=> - int(1) - [2]=> - string(3) "3rd" - ["4th"]=> - int(4) -} -external::get(0) -string(3) "1st" -external::get(1) -int(1) -external::get(2) -string(3) "3rd" -external::get(4th) -int(4) -external::get(5th) - -Notice: Undefined index: 5th in %s on line %d -NULL -external::get(6) - -Notice: Undefined offset: 6 in %s on line %d -NULL -external::exists(0) -external::get(0) -string(3) "1st" -external::exists(1) -external::get(1) -int(1) -external::exists(2) -external::get(2) -string(3) "3rd" -external::exists(4th) -external::get(4th) -int(4) -external::exists(5th) - -Notice: Undefined index: 5th in %s on line %d -NULL -external::exists(6) - -Notice: Undefined index: 6 in %s on line %d -NULL -external::exists(0) -external::get(0) -1st -external::exists(1) -external::get(1) -1 -external::exists(2) -external::get(2) -3rd -external::exists(4th) -external::get(4th) -4 -INTERNAL -array(4) { - [0]=> - string(3) "1st" - [1]=> - int(1) - [2]=> - string(3) "3rd" - ["4th"]=> - int(4) -} -internal::get(0) -string(3) "1st" -internal::get(1) -int(1) -internal::get(2) -string(3) "3rd" -internal::get(4th) -int(4) -internal::get(5th) - -Notice: Undefined index: 5th in %s on line %d -NULL -internal::get(6) - -Notice: Undefined offset: 6 in %s on line %d -NULL -internal::exists(0) -internal::get(0) -string(3) "1st" -internal::exists(1) -internal::get(1) -int(1) -internal::exists(2) -internal::get(2) -string(3) "3rd" -internal::exists(4th) -internal::get(4th) -int(4) -internal::exists(5th) - -Notice: Undefined index: 5th in %s on line %d -NULL -internal::exists(6) - -Notice: Undefined index: 6 in %s on line %d -NULL -internal::exists(0) -internal::get(0) -1st -internal::exists(1) -internal::get(1) -1 -internal::exists(2) -internal::get(2) -3rd -internal::exists(4th) -internal::get(4th) -4 -Done diff --git a/ext/spl/tests/foreach.phpt b/ext/spl/tests/foreach.phpt deleted file mode 100755 index 0a4cd91fb7..0000000000 --- a/ext/spl/tests/foreach.phpt +++ /dev/null @@ -1,202 +0,0 @@ ---TEST-- -SPL: foreach and iterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php -class c_iter implements spl_forward_assoc { - - private $obj; - private $num = 0; - - function __construct($obj) { - echo __METHOD__ . "\n"; - $this->num = 0; - $this->obj = $obj; - } - function current() { - echo __METHOD__ . "\n"; - return $this->num; - } - function next() { - echo __METHOD__ . "\n"; - $this->num++; - } - function hasMore() { - $more = $this->num < $this->obj->max; - echo __METHOD__ . ' = ' .($more ? 'true' : 'false') . "\n"; - return $more; - } - function key() { - echo __METHOD__ . "\n"; - switch($this->num) { - case 0: return "1st"; - case 1: return "2nd"; - case 2: return "3rd"; - default: return "???"; - } - } -} - -class c implements spl_iterator { - - public $max = 3; - - function newIterator() { - echo __METHOD__ . "\n"; - return new c_iter($this); - } -} - -$t = new c(); - -for ($iter = $t->newIterator(); $iter->hasMore(); $iter->next()) { - echo $iter->current() . "\n"; -} - -$a = array(0,1,2); -foreach($a as $v) { - echo "array:$v\n"; -} - -foreach($t as $v) { - echo "object:$v\n"; -} - -foreach($t as $v) { - foreach($t as $w) { - echo "double:$v:$w\n"; - } -} - -foreach($t as $i => $v) { - echo "object:$i=>$v\n"; -} - -print "Done\n"; -?> ---EXPECT-- -c::newIterator -c_iter::__construct -c_iter::hasMore = true -c_iter::current -0 -c_iter::next -c_iter::hasMore = true -c_iter::current -1 -c_iter::next -c_iter::hasMore = true -c_iter::current -2 -c_iter::next -c_iter::hasMore = false -array:0 -array:1 -array:2 -c::newIterator -c_iter::__construct -c_iter::hasMore = true -c_iter::current -c_iter::key -object:0 -c_iter::next -c_iter::hasMore = true -c_iter::current -c_iter::key -object:1 -c_iter::next -c_iter::hasMore = true -c_iter::current -c_iter::key -object:2 -c_iter::next -c_iter::hasMore = false -c::newIterator -c_iter::__construct -c_iter::hasMore = true -c_iter::current -c_iter::key -c::newIterator -c_iter::__construct -c_iter::hasMore = true -c_iter::current -c_iter::key -double:0:0 -c_iter::next -c_iter::hasMore = true -c_iter::current -c_iter::key -double:0:1 -c_iter::next -c_iter::hasMore = true -c_iter::current -c_iter::key -double:0:2 -c_iter::next -c_iter::hasMore = false -c_iter::next -c_iter::hasMore = true -c_iter::current -c_iter::key -c::newIterator -c_iter::__construct -c_iter::hasMore = true -c_iter::current -c_iter::key -double:1:0 -c_iter::next -c_iter::hasMore = true -c_iter::current -c_iter::key -double:1:1 -c_iter::next -c_iter::hasMore = true -c_iter::current -c_iter::key -double:1:2 -c_iter::next -c_iter::hasMore = false -c_iter::next -c_iter::hasMore = true -c_iter::current -c_iter::key -c::newIterator -c_iter::__construct -c_iter::hasMore = true -c_iter::current -c_iter::key -double:2:0 -c_iter::next -c_iter::hasMore = true -c_iter::current -c_iter::key -double:2:1 -c_iter::next -c_iter::hasMore = true -c_iter::current -c_iter::key -double:2:2 -c_iter::next -c_iter::hasMore = false -c_iter::next -c_iter::hasMore = false -c::newIterator -c_iter::__construct -c_iter::hasMore = true -c_iter::current -c_iter::key -object:1st=>0 -c_iter::next -c_iter::hasMore = true -c_iter::current -c_iter::key -object:2nd=>1 -c_iter::next -c_iter::hasMore = true -c_iter::current -c_iter::key -object:3rd=>2 -c_iter::next -c_iter::hasMore = false -Done diff --git a/ext/spl/tests/foreach_break.phpt b/ext/spl/tests/foreach_break.phpt deleted file mode 100755 index 184b762b84..0000000000 --- a/ext/spl/tests/foreach_break.phpt +++ /dev/null @@ -1,90 +0,0 @@ ---TEST-- -SPL: foreach and break ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php -class c_iter implements spl_forward_assoc { - - private $obj; - private $num = 0; - - function __construct($obj) { - $this->obj = $obj; - } - function current() { - echo __METHOD__ . "\n"; - return $this->num; - } - function next() { - echo __METHOD__ . "\n"; - $this->num++; - } - function hasMore() { - $more = $this->num < $this->obj->max; - echo __METHOD__ . ' = ' .($more ? 'true' : 'false') . "\n"; - return $more; - } - function key() { - echo __METHOD__ . "\n"; - switch($this->num) { - case 0: return "1st"; - case 1: return "2nd"; - case 2: return "3rd"; - default: return "???"; - } - } -} - -class c implements spl_iterator { - - public $max = 3; - - function newIterator() { - echo __METHOD__ . "\n"; - return new c_iter($this); - } -} - -$t = new c(); - -foreach($t as $v) { - foreach($t as $w) { - echo "double:$v:$w\n"; - break; - } -} - -print "Done\n"; -?> ---EXPECT-- -c::newIterator -c_iter::hasMore = true -c_iter::current -c_iter::key -c::newIterator -c_iter::hasMore = true -c_iter::current -c_iter::key -double:0:0 -c_iter::next -c_iter::hasMore = true -c_iter::current -c_iter::key -c::newIterator -c_iter::hasMore = true -c_iter::current -c_iter::key -double:1:0 -c_iter::next -c_iter::hasMore = true -c_iter::current -c_iter::key -c::newIterator -c_iter::hasMore = true -c_iter::current -c_iter::key -double:2:0 -c_iter::next -c_iter::hasMore = false -Done diff --git a/ext/spl/tests/foreach_continue.phpt b/ext/spl/tests/foreach_continue.phpt deleted file mode 100755 index 289f67e0a6..0000000000 --- a/ext/spl/tests/foreach_continue.phpt +++ /dev/null @@ -1,102 +0,0 @@ ---TEST-- -SPL: foreach and break ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php -class c_iter implements spl_forward { - - private $obj; - private $num = 0; - - function __construct($obj) { - $this->obj = $obj; - } - function current() { - echo __METHOD__ . "\n"; - return $this->num; - } - function next() { - echo __METHOD__ . "\n"; - $this->num++; - } - function hasMore() { - $more = $this->num < $this->obj->max; - echo __METHOD__ . ' = ' .($more ? 'true' : 'false') . "\n"; - return $more; - } -} - -class c implements spl_iterator { - - public $max = 4; - - function newIterator() { - echo __METHOD__ . "\n"; - return new c_iter($this); - } -} - -$t = new c(); - -foreach($t as $v) { - if ($v == 0) { - echo "continue outer\n"; - continue; - } - foreach($t as $w) { - if ($w == 1) { - echo "continue inner\n"; - continue; - } - if ($w == 2) { - echo "break inner\n"; - break; - } - echo "double:$v:$w\n"; - } - if ($v == 2) { - echo "break outer\n"; - break; - } -} - -print "Done\n"; -?> ---EXPECT-- -c::newIterator -c_iter::hasMore = true -c_iter::current -continue outer -c_iter::next -c_iter::hasMore = true -c_iter::current -c::newIterator -c_iter::hasMore = true -c_iter::current -double:1:0 -c_iter::next -c_iter::hasMore = true -c_iter::current -continue inner -c_iter::next -c_iter::hasMore = true -c_iter::current -break inner -c_iter::next -c_iter::hasMore = true -c_iter::current -c::newIterator -c_iter::hasMore = true -c_iter::current -double:2:0 -c_iter::next -c_iter::hasMore = true -c_iter::current -continue inner -c_iter::next -c_iter::hasMore = true -c_iter::current -break inner -break outer -Done diff --git a/ext/spl/tests/foreach_non_spl.phpt b/ext/spl/tests/foreach_non_spl.phpt deleted file mode 100755 index 71a7cb7f4d..0000000000 --- a/ext/spl/tests/foreach_non_spl.phpt +++ /dev/null @@ -1,61 +0,0 @@ ---TEST-- -SPL: foreach non spl classes ---SKIPIF-- -<?php if (0 && !extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -echo "1st try\n"; - -class c1 {} - -$obj = new c1(); - -foreach($obj as $w) { - echo "object:$w\n"; -} - -echo "2nd try\n"; - -class c2 { - - public $max = 3; - public $num = 0; - - function current() { - echo __METHOD__ . "\n"; - return $this->num; - } - function next() { - echo __METHOD__ . "\n"; - $this->num++; - } - function hasMore() { - echo __METHOD__ . "\n"; - return $this->num < $this->max; - } - function key() { - echo __METHOD__ . "\n"; - switch($this->num) { - case 0: return "1st"; - case 1: return "2nd"; - case 2: return "3rd"; - default: return "???"; - } - } -} - -$obj = new c2(); - -foreach($obj as $v => $w) { - echo "object:$v=>$w\n"; -} - -print "Done\n"; -?> ---EXPECTF-- -1st try -2nd try -object:max=>3 -object:num=>0 -Done diff --git a/ext/spl/tests/forward.phpt b/ext/spl/tests/forward.phpt deleted file mode 100755 index 8a14a52fe8..0000000000 --- a/ext/spl/tests/forward.phpt +++ /dev/null @@ -1,138 +0,0 @@ ---TEST-- -SPL: forward ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php -class c implements spl_forward_assoc { - - public $max = 3; - public $num = 0; - - function current() { - echo __METHOD__ . "\n"; - return $this->num; - } - function next() { - echo __METHOD__ . "\n"; - $this->num++; - } - function hasMore() { - echo __METHOD__ . "\n"; - return $this->num < $this->max; - } - function key() { - echo __METHOD__ . "\n"; - switch($this->num) { - case 0: return "1st"; - case 1: return "2nd"; - case 2: return "3rd"; - default: return "???"; - } - } -} - -$i = new c(); - -$implements = class_implements($i); -asort($implements); -$c_info = array(get_class($i) => array('inheits' => class_parents($i), 'implements' => $implements)); -print_r($c_info); -$methods = get_class_methods("spl_forward_assoc"); -sort($methods); -print_r($methods); -$methods = get_class_methods($i); -sort($methods); -print_r($methods); - - -echo "1st try\n"; -foreach($i as $w) { - echo "object:$w\n"; -} - -echo "2nd try\n"; - -foreach($i as $v => $w) { - echo "object:$v=>$w\n"; -} - -echo "3rd try\n"; -$i->num = 0; - -foreach($i as $v => $w) { - echo "object:$v=>$w\n"; -} - -print "Done\n"; -?> ---EXPECT-- -Array -( - [c] => Array - ( - [inheits] => Array - ( - ) - - [implements] => Array - ( - [spl_assoc] => spl_assoc - [spl_forward] => spl_forward - [spl_forward_assoc] => spl_forward_assoc - ) - - ) - -) -Array -( - [0] => current - [1] => hasMore - [2] => key - [3] => next -) -Array -( - [0] => current - [1] => hasMore - [2] => key - [3] => next -) -1st try -c::hasMore -c::current -c::key -object:0 -c::next -c::hasMore -c::current -c::key -object:1 -c::next -c::hasMore -c::current -c::key -object:2 -c::next -c::hasMore -2nd try -c::hasMore -3rd try -c::hasMore -c::current -c::key -object:1st=>0 -c::next -c::hasMore -c::current -c::key -object:2nd=>1 -c::next -c::hasMore -c::current -c::key -object:3rd=>2 -c::next -c::hasMore -Done diff --git a/ext/spl/tests/sequence.phpt b/ext/spl/tests/sequence.phpt deleted file mode 100755 index 34ea7fd8d5..0000000000 --- a/ext/spl/tests/sequence.phpt +++ /dev/null @@ -1,143 +0,0 @@ ---TEST-- -SPL: sequence ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php -class c implements spl_iterator { - - public $max = 3; - - function newIterator() { - echo __METHOD__ . "\n"; - return new c_iter($this); - } -} - -class c_iter implements spl_sequence_assoc { - - private $obj; - private $num = 0; - - function __construct($obj) { - $this->obj = $obj; - } - function rewind() { - echo __METHOD__ . "\n"; - $this->num = 0; - } - function current() { - echo __METHOD__ . "\n"; - return $this->num; - } - function next() { - echo __METHOD__ . "\n"; - $this->num++; - } - function hasMore() { - echo __METHOD__ . "\n"; - return $this->num < $this->obj->max; - } - function key() { - echo __METHOD__ . "\n"; - switch($this->num) { - case 0: return "1st"; - case 1: return "2nd"; - case 2: return "3rd"; - default: return "???"; - } - } -} - -$t = new c(); -$i = $t->newIterator(); - -$implements_t = class_implements($t); -asort($implements_t); -$implements_i = class_implements($i); -asort($implements_i); - -$c_info = array(get_class($t) => array('inheits' => class_parents($t), 'implements' => $implements_t), - get_class($i) => array('inheits' => class_parents($i), 'implements' => $implements_i)); -print_r($c_info); - -foreach($i as $w) { - echo "object:$w\n"; -} - -foreach($i as $v => $w) { - echo "object:$v=>$w\n"; -} - -print "Done\n"; -?> ---EXPECT-- -c::newIterator -Array -( - [c] => Array - ( - [inheits] => Array - ( - ) - - [implements] => Array - ( - [spl_iterator] => spl_iterator - ) - - ) - - [c_iter] => Array - ( - [inheits] => Array - ( - ) - - [implements] => Array - ( - [spl_assoc] => spl_assoc - [spl_forward] => spl_forward - [spl_forward_assoc] => spl_forward_assoc - [spl_sequence] => spl_sequence - [spl_sequence_assoc] => spl_sequence_assoc - ) - - ) - -) -c_iter::rewind -c_iter::hasMore -c_iter::current -c_iter::key -object:0 -c_iter::next -c_iter::hasMore -c_iter::current -c_iter::key -object:1 -c_iter::next -c_iter::hasMore -c_iter::current -c_iter::key -object:2 -c_iter::next -c_iter::hasMore -c_iter::rewind -c_iter::hasMore -c_iter::current -c_iter::key -object:1st=>0 -c_iter::next -c_iter::hasMore -c_iter::current -c_iter::key -object:2nd=>1 -c_iter::next -c_iter::hasMore -c_iter::current -c_iter::key -object:3rd=>2 -c_iter::next -c_iter::hasMore -Done
\ No newline at end of file |