diff options
| author | Sean Finney <seanius@debian.org> | 2009-06-24 22:49:04 +0200 |
|---|---|---|
| committer | Sean Finney <seanius@debian.org> | 2009-06-24 22:49:04 +0200 |
| commit | 84f4ca9b07fe5b73d840258f4aa7c1eb534c4253 (patch) | |
| tree | 9829bd578af8a4a8b42b04277f9067e00dc5ad90 /ext/spl | |
| parent | 6821b67124604da690c5e9276d5370d679c63ac8 (diff) | |
| download | php-84f4ca9b07fe5b73d840258f4aa7c1eb534c4253.tar.gz | |
Imported Upstream version 5.3.0~RC4upstream/5.3.0_RC4upstream/5.3.0.RC4
Diffstat (limited to 'ext/spl')
220 files changed, 6096 insertions, 2010 deletions
diff --git a/ext/spl/internal/appenditerator.inc b/ext/spl/internal/appenditerator.inc index 74f254d11..5db080425 100755 --- a/ext/spl/internal/appenditerator.inc +++ b/ext/spl/internal/appenditerator.inc @@ -4,7 +4,7 @@ * @ingroup SPL * @brief class AppendIterator * @author Marcus Boerger - * @date 2003 - 2005 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ diff --git a/ext/spl/internal/cachingiterator.inc b/ext/spl/internal/cachingiterator.inc index 6714821f6..7262564f2 100755 --- a/ext/spl/internal/cachingiterator.inc +++ b/ext/spl/internal/cachingiterator.inc @@ -1,157 +1,157 @@ -<?php
-
-/** @file cachingiterator.inc
- * @ingroup SPL
- * @brief class CachingIterator
- * @author Marcus Boerger
- * @date 2003 - 2005
- *
- * SPL - Standard PHP Library
- */
-
-/**
- * @brief Cached iteration over another Iterator
- * @author Marcus Boerger
- * @version 1.2
- * @since PHP 5.0
- *
- * This iterator wrapper does a one ahead iteration. This way it knows whether
- * the inner iterator has one more element.
- *
- * @note If you want to convert the elements into strings and the inner
- * Iterator is an internal Iterator then you need to provide the
- * flag CALL_TOSTRING to do the conversion when the actual element
- * is being fetched. Otherwise the conversion would happen with the
- * already changed iterator. If you do not need this then it you should
- * omit this flag because it costs unneccessary work and time.
- */
-class CachingIterator implements OuterIterator
-{
- const CALL_TOSTRING = 0x00000001;
- const CATCH_GET_CHILD = 0x00000002;
- const TOSTRING_USE_KEY = 0x00000010;
- const TOSTRING_USE_CURRENT = 0x00000020;
-
- private $it;
- private $current;
- private $key;
- private $valid;
- private $strValue;
-
- /** Construct from another iterator
- *
- * @param it Iterator to cache
- * @param flags Bitmask:
- * - CALL_TOSTRING (whether to call __toString() for every element)
- */
- function __construct(Iterator $it, $flags = self::CALL_TOSTRING)
- {
- if ((($flags & self::CALL_TOSTRING) && ($flags & (self::TOSTRING_USE_KEY|self::TOSTRING_USE_CURRENT)))
- || ((flags & (self::CIT_TOSTRING_USE_KEY|self::CIT_TOSTRING_USE_CURRENT)) == (self::CIT_TOSTRING_USE_KEY|self::CIT_TOSTRING_USE_CURRENT)))
- {
- throw new InvalidArgumentException('Flags must contain only one of CIT_CALL_TOSTRING, CIT_TOSTRING_USE_KEY, CIT_TOSTRING_USE_CURRENT');
- }
- $this->it = $it;
- $this->flags = $flags & (0x0000FFFF);
- $this->next();
- }
-
- /** Rewind the Iterator
- */
- function rewind()
- {
- $this->it->rewind();
- $this->next();
- }
-
- /** Forward to the next element
- */
- function next()
- {
- if ($this->valid = $this->it->valid()) {
- $this->current = $this->it->current();
- $this->key = $this->it->key();
- if ($this->flags & self::CALL_TOSTRING) {
- if (is_object($this->current)) {
- $this->strValue = $this->current->__toString();
- } else {
- $this->strValue = (string)$this->current;
- }
- }
- } else {
- $this->current = NULL;
- $this->key = NULL;
- $this->strValue = NULL;
- }
- $this->it->next();
- }
-
- /** @return whether teh iterator is valid
- */
- function valid()
- {
- return $this->valid;
- }
-
- /** @return whether there is one more element
- */
- function hasNext()
- {
- return $this->it->valid();
- }
-
- /** @return the current element
- */
- function current()
- {
- return $this->current;
- }
-
- /** @return the current key
- */
- function key()
- {
- return $this->key;
- }
-
- /** Aggregate the inner iterator
- *
- * @param func Name of method to invoke
- * @param params Array of parameters to pass to method
- */
- function __call($func, $params)
- {
- return call_user_func_array(array($this->it, $func), $params);
- }
-
- /** @return the string represenatation that was generated for the current
- * element
- * @throw exception when CALL_TOSTRING was not specified in constructor
- */
- function __toString()
- {
- if ($this->flags & self::TOSTRING_USE_KEY)
- {
- return $this->key;
- }
- else if ($this->flags & self::TOSTRING_USE_CURRENT)
- {
- return $this->current;
- }
- if (!$this->flags & self::CALL_TOSTRING)
- {
- throw new exception('CachingIterator does not fetch string value (see CachingIterator::__construct)');
- }
- return $this->strValue;
- }
-
- /**
- * @return The inner iterator
- */
- function getInnerIterator()
- {
- return $this->it;
- }
-}
-
+<?php + +/** @file cachingiterator.inc + * @ingroup SPL + * @brief class CachingIterator + * @author Marcus Boerger + * @date 2003 - 2009 + * + * SPL - Standard PHP Library + */ + +/** + * @brief Cached iteration over another Iterator + * @author Marcus Boerger + * @version 1.2 + * @since PHP 5.0 + * + * This iterator wrapper does a one ahead iteration. This way it knows whether + * the inner iterator has one more element. + * + * @note If you want to convert the elements into strings and the inner + * Iterator is an internal Iterator then you need to provide the + * flag CALL_TOSTRING to do the conversion when the actual element + * is being fetched. Otherwise the conversion would happen with the + * already changed iterator. If you do not need this then it you should + * omit this flag because it costs unneccessary work and time. + */ +class CachingIterator implements OuterIterator +{ + const CALL_TOSTRING = 0x00000001; + const CATCH_GET_CHILD = 0x00000002; + const TOSTRING_USE_KEY = 0x00000010; + const TOSTRING_USE_CURRENT = 0x00000020; + + private $it; + private $current; + private $key; + private $valid; + private $strValue; + + /** Construct from another iterator + * + * @param it Iterator to cache + * @param flags Bitmask: + * - CALL_TOSTRING (whether to call __toString() for every element) + */ + function __construct(Iterator $it, $flags = self::CALL_TOSTRING) + { + if ((($flags & self::CALL_TOSTRING) && ($flags & (self::TOSTRING_USE_KEY|self::TOSTRING_USE_CURRENT))) + || ((flags & (self::CIT_TOSTRING_USE_KEY|self::CIT_TOSTRING_USE_CURRENT)) == (self::CIT_TOSTRING_USE_KEY|self::CIT_TOSTRING_USE_CURRENT))) + { + throw new InvalidArgumentException('Flags must contain only one of CIT_CALL_TOSTRING, CIT_TOSTRING_USE_KEY, CIT_TOSTRING_USE_CURRENT'); + } + $this->it = $it; + $this->flags = $flags & (0x0000FFFF); + $this->next(); + } + + /** Rewind the Iterator + */ + function rewind() + { + $this->it->rewind(); + $this->next(); + } + + /** Forward to the next element + */ + function next() + { + if ($this->valid = $this->it->valid()) { + $this->current = $this->it->current(); + $this->key = $this->it->key(); + if ($this->flags & self::CALL_TOSTRING) { + if (is_object($this->current)) { + $this->strValue = $this->current->__toString(); + } else { + $this->strValue = (string)$this->current; + } + } + } else { + $this->current = NULL; + $this->key = NULL; + $this->strValue = NULL; + } + $this->it->next(); + } + + /** @return whether teh iterator is valid + */ + function valid() + { + return $this->valid; + } + + /** @return whether there is one more element + */ + function hasNext() + { + return $this->it->valid(); + } + + /** @return the current element + */ + function current() + { + return $this->current; + } + + /** @return the current key + */ + function key() + { + return $this->key; + } + + /** Aggregate the inner iterator + * + * @param func Name of method to invoke + * @param params Array of parameters to pass to method + */ + function __call($func, $params) + { + return call_user_func_array(array($this->it, $func), $params); + } + + /** @return the string represenatation that was generated for the current + * element + * @throw exception when CALL_TOSTRING was not specified in constructor + */ + function __toString() + { + if ($this->flags & self::TOSTRING_USE_KEY) + { + return $this->key; + } + else if ($this->flags & self::TOSTRING_USE_CURRENT) + { + return $this->current; + } + if (!$this->flags & self::CALL_TOSTRING) + { + throw new exception('CachingIterator does not fetch string value (see CachingIterator::__construct)'); + } + return $this->strValue; + } + + /** + * @return The inner iterator + */ + function getInnerIterator() + { + return $this->it; + } +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/emptyiterator.inc b/ext/spl/internal/emptyiterator.inc index a72a8b1a4..ac80e7958 100755 --- a/ext/spl/internal/emptyiterator.inc +++ b/ext/spl/internal/emptyiterator.inc @@ -1,62 +1,62 @@ -<?php
-
-/** @file emptyiterator.inc
- * @ingroup SPL
- * @brief class EmptyIterator
- * @author Marcus Boerger
- * @date 2003 - 2005
- *
- * SPL - Standard PHP Library
- */
-
-/** @ingroup SPL
- * @brief An empty Iterator
- * @author Marcus Boerger
- * @version 1.0
- * @since PHP 5.1
- */
-class EmptyIterator implements Iterator
-{
- /** No operation.
- * @return void
- */
- function rewind()
- {
- // nothing to do
- }
-
- /** @return \c false
- */
- function valid()
- {
- return false;
- }
-
- /** This function must not be called. It throws an exception upon access.
- * @throw Exception
- * @return void
- */
- function current()
- {
- throw new Exception('Accessing the value of an EmptyIterator');
- }
-
- /** This function must not be called. It throws an exception upon access.
- * @throw Exception
- * @return void
- */
- function key()
- {
- throw new Exception('Accessing the key of an EmptyIterator');
- }
-
- /** No operation.
- * @return void
- */
- function next()
- {
- // nothing to do
- }
-}
-
+<?php + +/** @file emptyiterator.inc + * @ingroup SPL + * @brief class EmptyIterator + * @author Marcus Boerger + * @date 2003 - 2009 + * + * SPL - Standard PHP Library + */ + +/** @ingroup SPL + * @brief An empty Iterator + * @author Marcus Boerger + * @version 1.0 + * @since PHP 5.1 + */ +class EmptyIterator implements Iterator +{ + /** No operation. + * @return void + */ + function rewind() + { + // nothing to do + } + + /** @return \c false + */ + function valid() + { + return false; + } + + /** This function must not be called. It throws an exception upon access. + * @throw Exception + * @return void + */ + function current() + { + throw new Exception('Accessing the value of an EmptyIterator'); + } + + /** This function must not be called. It throws an exception upon access. + * @throw Exception + * @return void + */ + function key() + { + throw new Exception('Accessing the key of an EmptyIterator'); + } + + /** No operation. + * @return void + */ + function next() + { + // nothing to do + } +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/filteriterator.inc b/ext/spl/internal/filteriterator.inc index c0b5681d2..3330cc9e4 100755 --- a/ext/spl/internal/filteriterator.inc +++ b/ext/spl/internal/filteriterator.inc @@ -1,127 +1,127 @@ -<?php
-
+<?php + /** @file filteriterator.inc * @ingroup SPL * @brief class FilterIterator * @author Marcus Boerger - * @date 2003 - 2006 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/**
- * @brief Abstract filter for iterators
- * @author Marcus Boerger
- * @version 1.1
- * @since PHP 5.0
- *
- * Instances of this class act as a filter around iterators. In other words
- * you can put an iterator into the constructor and the instance will only
- * return selected (accepted) elements.
- *
- * The only thing that needs to be done to make this work is implementing
- * method accept(). Typically this invloves reading the current element or
- * key of the inner Iterator and checking whether it is acceptable.
- */
-abstract class FilterIterator implements OuterIterator
-{
- private $it;
-
- /**
- * Constructs a filter around another iterator.
- *
- * @param it Iterator to filter
- */
- function __construct(Iterator $it) {
- $this->it = $it;
- }
-
- /**
- * Rewind the inner iterator.
- */
- function rewind() {
- $this->it->rewind();
- $this->fetch();
- }
-
- /**
- * Accept function to decide whether an element of the inner iterator
- * should be accessible through the Filteriterator.
- *
- * @return whether or not to expose the current element of the inner
- * iterator.
- */
- abstract function accept();
-
- /**
- * Fetch next element and store it.
- *
- * @return void
- */
- protected function fetch() {
- while ($this->it->valid()) {
- if ($this->accept()) {
- return;
- }
- $this->it->next();
- };
- }
-
- /**
- * Move to next element
- *
- * @return void
- */
- function next() {
- $this->it->next();
- $this->fetch();
- }
-
- /**
- * @return Whether more elements are available
- */
- function valid() {
- return $this->it->valid();
- }
-
- /**
- * @return The current key
- */
- function key() {
- return $this->it->key();
- }
-
- /**
- * @return The current value
- */
- function current() {
- return $this->it->current();
- }
-
- /**
- * hidden __clone
- */
- protected function __clone() {
- // disallow clone
- }
-
- /**
- * @return The inner iterator
- */
- function getInnerIterator()
- {
- return $this->it;
- }
-
- /** Aggregate the inner iterator
- *
- * @param func Name of method to invoke
- * @param params Array of parameters to pass to method
- */
- function __call($func, $params)
- {
- return call_user_func_array(array($this->it, $func), $params);
- }
-}
-
+/** + * @brief Abstract filter for iterators + * @author Marcus Boerger + * @version 1.1 + * @since PHP 5.0 + * + * Instances of this class act as a filter around iterators. In other words + * you can put an iterator into the constructor and the instance will only + * return selected (accepted) elements. + * + * The only thing that needs to be done to make this work is implementing + * method accept(). Typically this invloves reading the current element or + * key of the inner Iterator and checking whether it is acceptable. + */ +abstract class FilterIterator implements OuterIterator +{ + private $it; + + /** + * Constructs a filter around another iterator. + * + * @param it Iterator to filter + */ + function __construct(Iterator $it) { + $this->it = $it; + } + + /** + * Rewind the inner iterator. + */ + function rewind() { + $this->it->rewind(); + $this->fetch(); + } + + /** + * Accept function to decide whether an element of the inner iterator + * should be accessible through the Filteriterator. + * + * @return whether or not to expose the current element of the inner + * iterator. + */ + abstract function accept(); + + /** + * Fetch next element and store it. + * + * @return void + */ + protected function fetch() { + while ($this->it->valid()) { + if ($this->accept()) { + return; + } + $this->it->next(); + }; + } + + /** + * Move to next element + * + * @return void + */ + function next() { + $this->it->next(); + $this->fetch(); + } + + /** + * @return Whether more elements are available + */ + function valid() { + return $this->it->valid(); + } + + /** + * @return The current key + */ + function key() { + return $this->it->key(); + } + + /** + * @return The current value + */ + function current() { + return $this->it->current(); + } + + /** + * hidden __clone + */ + protected function __clone() { + // disallow clone + } + + /** + * @return The inner iterator + */ + function getInnerIterator() + { + return $this->it; + } + + /** Aggregate the inner iterator + * + * @param func Name of method to invoke + * @param params Array of parameters to pass to method + */ + function __call($func, $params) + { + return call_user_func_array(array($this->it, $func), $params); + } +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/infiniteiterator.inc b/ext/spl/internal/infiniteiterator.inc index 2dbe8d865..04d782718 100755 --- a/ext/spl/internal/infiniteiterator.inc +++ b/ext/spl/internal/infiniteiterator.inc @@ -1,48 +1,48 @@ -<?php
-
-/** @file infiniteiterator.inc
- * @ingroup SPL
- * @brief class InfiniteIterator
- * @author Marcus Boerger
- * @date 2003 - 2005
- *
- * SPL - Standard PHP Library
- */
-
-/** @ingroup SPL
- * @brief An infinite Iterator
- * @author Marcus Boerger
- * @version 1.1
- * @since PHP 5.1
- *
- * This Iterator takes another Iterator and infinitvely iterates it by
- * rewinding it when its end is reached.
- *
- * \note Even an InfiniteIterator stops if its inner Iterator is empty.
- *
- \verbatim
- $it = new ArrayIterator(array(1,2,3));
- $infinite = new InfiniteIterator($it);
- $limit = new LimitIterator($infinite, 0, 5);
- foreach($limit as $val=>$key)
- {
- echo "$val=>$key\n";
- }
- \endverbatim
- */
-class InfiniteIterator extends IteratorIterator
-{
- /** Move the inner Iterator forward to its next element or rewind it.
- * @return void
- */
- function next()
- {
- $this->getInnerIterator()->next();
- if (!$this->getInnerIterator()->valid())
- {
- $this->getInnerIterator()->rewind();
- }
- }
-}
-
+<?php + +/** @file infiniteiterator.inc + * @ingroup SPL + * @brief class InfiniteIterator + * @author Marcus Boerger + * @date 2003 - 2009 + * + * SPL - Standard PHP Library + */ + +/** @ingroup SPL + * @brief An infinite Iterator + * @author Marcus Boerger + * @version 1.1 + * @since PHP 5.1 + * + * This Iterator takes another Iterator and infinitvely iterates it by + * rewinding it when its end is reached. + * + * \note Even an InfiniteIterator stops if its inner Iterator is empty. + * + \verbatim + $it = new ArrayIterator(array(1,2,3)); + $infinite = new InfiniteIterator($it); + $limit = new LimitIterator($infinite, 0, 5); + foreach($limit as $val=>$key) + { + echo "$val=>$key\n"; + } + \endverbatim + */ +class InfiniteIterator extends IteratorIterator +{ + /** Move the inner Iterator forward to its next element or rewind it. + * @return void + */ + function next() + { + $this->getInnerIterator()->next(); + if (!$this->getInnerIterator()->valid()) + { + $this->getInnerIterator()->rewind(); + } + } +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/iteratoriterator.inc b/ext/spl/internal/iteratoriterator.inc index 13c717523..37676e053 100755 --- a/ext/spl/internal/iteratoriterator.inc +++ b/ext/spl/internal/iteratoriterator.inc @@ -1,121 +1,121 @@ -<?php
-
-/** @file iteratoriterator.inc
- * @ingroup SPL
- * @brief class IteratorIterator
- * @author Marcus Boerger
- * @date 2003 - 2005
- *
- * SPL - Standard PHP Library
- */
-
-/** @ingroup SPL
- * @brief Basic Iterator wrapper
- * @since PHP 5.1
- *
- * This iterator wrapper allows to convert anything that is traversable into
- * an Iterator. It is very important to understand that most classes that do
- * not implement Iterator have their reasone to. Most likely they do not allow
- * the full Iterator feature set. If so you need to provide techniques to
- * prevent missuse. If you do not you must expect exceptions or fatal erros.
- *
- * It is also possible to derive the class and implement IteratorAggregate by
- * downcasting the instances returned in getIterator. See the following
- * example (assuming BaseClass implements Traversable):
- \code
- class SomeClass extends BaseClass implements IteratorAggregate
- {
- function getIterator()
- {
- return new IteratorIterator($this, 'BaseClass');
- }
- }
- \endcode
- *
- * As you can see in the example this approach requires that the class to
- * downcast to is actually a base class of the specified iterator to wrap.
- * Omitting the downcast in the above example would result in an endless loop
- * since IteratorIterator::__construct() would call SomeClass::getIterator().
- */
-class IteratorIterator implements OuterIterator
-{
- /** Construct an IteratorIterator from an Iterator or an IteratorAggregate.
- *
- * @param iterator inner iterator
- * @param classname optional class the iterator has to be downcasted to
- */
- function __construct(Traversable $iterator, $classname = null)
- {
- if ($iterator instanceof IteratorAggregate)
- {
- $iterator = $iterator->getIterator();
- }
- if ($iterator instanceof Iterator)
- {
- $this->iterator = $iterator;
- }
- else
- {
- throw new Exception("Classes that only implement Traversable can be wrapped only after converting class IteratorIterator into c code");
- }
- }
-
- /** \return the inner iterator as passed to the constructor
- */
- function getInnerIterator()
- {
- return $this->iterator;
- }
-
- /** \return whether the iterator is valid
- */
- function valid()
- {
- return $this->iterator->valid();
- }
-
- /** \return current key
- */
- function key()
- {
- return $this->iterator->key();
- }
-
- /** \return current value
- */
- function current()
- {
- return $this->iterator->current();
- }
-
- /** forward to next element
- */
- function next()
- {
- return $this->iterator->next();
- }
-
- /** rewind to the first element
- */
- function rewind()
- {
- return $this->iterator->rewind();
- }
-
- /** Aggregate the inner iterator
- *
- * @param func Name of method to invoke
- * @param params Array of parameters to pass to method
- */
- function __call($func, $params)
- {
- return call_user_func_array(array($this->iterator, $func), $params);
- }
-
- /** The inner iterator must be private because when this class will be
- * converted to c code it won't no longer be available.
- */
- private $iterator;
-}
-
-?>
+<?php + +/** @file iteratoriterator.inc + * @ingroup SPL + * @brief class IteratorIterator + * @author Marcus Boerger + * @date 2003 - 2009 + * + * SPL - Standard PHP Library + */ + +/** @ingroup SPL + * @brief Basic Iterator wrapper + * @since PHP 5.1 + * + * This iterator wrapper allows to convert anything that is traversable into + * an Iterator. It is very important to understand that most classes that do + * not implement Iterator have their reasone to. Most likely they do not allow + * the full Iterator feature set. If so you need to provide techniques to + * prevent missuse. If you do not you must expect exceptions or fatal erros. + * + * It is also possible to derive the class and implement IteratorAggregate by + * downcasting the instances returned in getIterator. See the following + * example (assuming BaseClass implements Traversable): + \code + class SomeClass extends BaseClass implements IteratorAggregate + { + function getIterator() + { + return new IteratorIterator($this, 'BaseClass'); + } + } + \endcode + * + * As you can see in the example this approach requires that the class to + * downcast to is actually a base class of the specified iterator to wrap. + * Omitting the downcast in the above example would result in an endless loop + * since IteratorIterator::__construct() would call SomeClass::getIterator(). + */ +class IteratorIterator implements OuterIterator +{ + /** Construct an IteratorIterator from an Iterator or an IteratorAggregate. + * + * @param iterator inner iterator + * @param classname optional class the iterator has to be downcasted to + */ + function __construct(Traversable $iterator, $classname = null) + { + if ($iterator instanceof IteratorAggregate) + { + $iterator = $iterator->getIterator(); + } + if ($iterator instanceof Iterator) + { + $this->iterator = $iterator; + } + else + { + throw new Exception("Classes that only implement Traversable can be wrapped only after converting class IteratorIterator into c code"); + } + } + + /** \return the inner iterator as passed to the constructor + */ + function getInnerIterator() + { + return $this->iterator; + } + + /** \return whether the iterator is valid + */ + function valid() + { + return $this->iterator->valid(); + } + + /** \return current key + */ + function key() + { + return $this->iterator->key(); + } + + /** \return current value + */ + function current() + { + return $this->iterator->current(); + } + + /** forward to next element + */ + function next() + { + return $this->iterator->next(); + } + + /** rewind to the first element + */ + function rewind() + { + return $this->iterator->rewind(); + } + + /** Aggregate the inner iterator + * + * @param func Name of method to invoke + * @param params Array of parameters to pass to method + */ + function __call($func, $params) + { + return call_user_func_array(array($this->iterator, $func), $params); + } + + /** The inner iterator must be private because when this class will be + * converted to c code it won't no longer be available. + */ + private $iterator; +} + +?> diff --git a/ext/spl/internal/limititerator.inc b/ext/spl/internal/limititerator.inc index c135e031d..c5bddead7 100755 --- a/ext/spl/internal/limititerator.inc +++ b/ext/spl/internal/limititerator.inc @@ -1,134 +1,134 @@ -<?php
-
+<?php + /** @file limititerator.inc * @ingroup SPL * @brief class LimitIterator * @author Marcus Boerger - * @date 2003 - 2005 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/**
- * @brief Limited Iteration over another Iterator
- * @author Marcus Boerger
- * @version 1.1
- * @since PHP 5.0
- *
- * A class that starts iteration at a certain offset and only iterates over
- * a specified amount of elements.
- *
- * This class uses SeekableIterator::seek() if available and rewind() plus
- * a skip loop otehrwise.
- */
-class LimitIterator implements OuterIterator
-{
- private $it;
- private $offset;
- private $count;
- private $pos;
-
- /** Construct
- *
- * @param it Iterator to limit
- * @param offset Offset to first element
- * @param count Maximum number of elements to show or -1 for all
- */
- function __construct(Iterator $it, $offset = 0, $count = -1)
- {
- if ($offset < 0) {
- throw new exception('Parameter offset must be > 0');
- }
- if ($count < 0 && $count != -1) {
- throw new exception('Parameter count must either be -1 or a value greater than or equal to 0');
- }
- $this->it = $it;
- $this->offset = $offset;
- $this->count = $count;
- $this->pos = 0;
- }
-
- /** Seek to specified position
- * @param position offset to seek to (relative to beginning not offset
- * specified in constructor).
- * @throw exception when position is invalid
- */
- function seek($position) {
- if ($position < $this->offset) {
- throw new exception('Cannot seek to '.$position.' which is below offset '.$this->offset);
- }
- if ($position > $this->offset + $this->count && $this->count != -1) {
- throw new exception('Cannot seek to '.$position.' which is behind offset '.$this->offset.' plus count '.$this->count);
- }
- if ($this->it instanceof SeekableIterator) {
- $this->it->seek($position);
- $this->pos = $position;
- } else {
- while($this->pos < $position && $this->it->valid()) {
- $this->next();
- }
- }
- }
-
- /** Rewind to offset specified in constructor
- */
- function rewind()
- {
- $this->it->rewind();
- $this->pos = 0;
- $this->seek($this->offset);
- }
-
- /** @return whether iterator is valid
- */
- function valid() {
- return ($this->count == -1 || $this->pos < $this->offset + $this->count)
- && $this->it->valid();
- }
-
- /** @return current key
- */
- function key() {
- return $this->it->key();
- }
-
- /** @return current element
- */
- function current() {
- return $this->it->current();
- }
-
- /** Forward to nect element
- */
- function next() {
- $this->it->next();
- $this->pos++;
- }
-
- /** @return current position relative to zero (not to offset specified in
- * constructor).
- */
- function getPosition() {
- return $this->pos;
- }
-
- /**
- * @return The inner iterator
- */
- function getInnerIterator()
- {
- return $this->it;
- }
-
- /** Aggregate the inner iterator
- *
- * @param func Name of method to invoke
- * @param params Array of parameters to pass to method
- */
- function __call($func, $params)
- {
- return call_user_func_array(array($this->it, $func), $params);
- }
-}
-
+/** + * @brief Limited Iteration over another Iterator + * @author Marcus Boerger + * @version 1.1 + * @since PHP 5.0 + * + * A class that starts iteration at a certain offset and only iterates over + * a specified amount of elements. + * + * This class uses SeekableIterator::seek() if available and rewind() plus + * a skip loop otehrwise. + */ +class LimitIterator implements OuterIterator +{ + private $it; + private $offset; + private $count; + private $pos; + + /** Construct + * + * @param it Iterator to limit + * @param offset Offset to first element + * @param count Maximum number of elements to show or -1 for all + */ + function __construct(Iterator $it, $offset = 0, $count = -1) + { + if ($offset < 0) { + throw new exception('Parameter offset must be > 0'); + } + if ($count < 0 && $count != -1) { + throw new exception('Parameter count must either be -1 or a value greater than or equal to 0'); + } + $this->it = $it; + $this->offset = $offset; + $this->count = $count; + $this->pos = 0; + } + + /** Seek to specified position + * @param position offset to seek to (relative to beginning not offset + * specified in constructor). + * @throw exception when position is invalid + */ + function seek($position) { + if ($position < $this->offset) { + throw new exception('Cannot seek to '.$position.' which is below offset '.$this->offset); + } + if ($position > $this->offset + $this->count && $this->count != -1) { + throw new exception('Cannot seek to '.$position.' which is behind offset '.$this->offset.' plus count '.$this->count); + } + if ($this->it instanceof SeekableIterator) { + $this->it->seek($position); + $this->pos = $position; + } else { + while($this->pos < $position && $this->it->valid()) { + $this->next(); + } + } + } + + /** Rewind to offset specified in constructor + */ + function rewind() + { + $this->it->rewind(); + $this->pos = 0; + $this->seek($this->offset); + } + + /** @return whether iterator is valid + */ + function valid() { + return ($this->count == -1 || $this->pos < $this->offset + $this->count) + && $this->it->valid(); + } + + /** @return current key + */ + function key() { + return $this->it->key(); + } + + /** @return current element + */ + function current() { + return $this->it->current(); + } + + /** Forward to nect element + */ + function next() { + $this->it->next(); + $this->pos++; + } + + /** @return current position relative to zero (not to offset specified in + * constructor). + */ + function getPosition() { + return $this->pos; + } + + /** + * @return The inner iterator + */ + function getInnerIterator() + { + return $this->it; + } + + /** Aggregate the inner iterator + * + * @param func Name of method to invoke + * @param params Array of parameters to pass to method + */ + function __call($func, $params) + { + return call_user_func_array(array($this->it, $func), $params); + } +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/multipleiterator.inc b/ext/spl/internal/multipleiterator.inc index e977ca369..2ed71d53a 100755 --- a/ext/spl/internal/multipleiterator.inc +++ b/ext/spl/internal/multipleiterator.inc @@ -4,7 +4,7 @@ * @brief class MultipleIterator * @author Johannes Schlueter * @author Marcus Boerger - * @date 2008 + * @date 2008 - 2009 * * SPL - Standard PHP Library */ diff --git a/ext/spl/internal/norewinditerator.inc b/ext/spl/internal/norewinditerator.inc index 296fe2b92..8747a6116 100755 --- a/ext/spl/internal/norewinditerator.inc +++ b/ext/spl/internal/norewinditerator.inc @@ -1,28 +1,28 @@ -<?php
-
-/** @file norewinditerator.inc
- * @ingroup SPL
- * @brief class NoRewindIterator
- * @author Marcus Boerger
- * @date 2003 - 2005
- *
- * SPL - Standard PHP Library
- */
-
-/** @ingroup SPL
- * @brief An Iterator wrapper that doesn't call rewind
- * @author Marcus Boerger
- * @version 1.1
- * @since PHP 5.1
- */
-class NoRewindIterator extends IteratorIterator
-{
- /** Simply prevent execution of inner iterators rewind().
- */
- function rewind()
- {
- // nothing to do
- }
-}
-
+<?php + +/** @file norewinditerator.inc + * @ingroup SPL + * @brief class NoRewindIterator + * @author Marcus Boerger + * @date 2003 - 2009 + * + * SPL - Standard PHP Library + */ + +/** @ingroup SPL + * @brief An Iterator wrapper that doesn't call rewind + * @author Marcus Boerger + * @version 1.1 + * @since PHP 5.1 + */ +class NoRewindIterator extends IteratorIterator +{ + /** Simply prevent execution of inner iterators rewind(). + */ + function rewind() + { + // nothing to do + } +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/outeriterator.inc b/ext/spl/internal/outeriterator.inc index d3068f029..f26d29da5 100755 --- a/ext/spl/internal/outeriterator.inc +++ b/ext/spl/internal/outeriterator.inc @@ -1,25 +1,25 @@ -<?php
-
+<?php + /** @file outeriterator.inc * @ingroup SPL * @brief class OuterIterator * @author Marcus Boerger - * @date 2003 - 2005 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/**
- * @brief Interface to access the current inner iteraor of iterator wrappers
- * @author Marcus Boerger
- * @version 1.0
- * @since PHP 5.1
- */
-interface OuterIterator extends Iterator
-{
- /** @return inner iterator
- */
- function getInnerIterator();
-}
-
+/** + * @brief Interface to access the current inner iteraor of iterator wrappers + * @author Marcus Boerger + * @version 1.0 + * @since PHP 5.1 + */ +interface OuterIterator extends Iterator +{ + /** @return inner iterator + */ + function getInnerIterator(); +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/parentiterator.inc b/ext/spl/internal/parentiterator.inc index 84c760d62..cc377fcc6 100755 --- a/ext/spl/internal/parentiterator.inc +++ b/ext/spl/internal/parentiterator.inc @@ -1,32 +1,32 @@ -<?php
-
+<?php + /** @file parentiterator.inc * @ingroup SPL * @brief class FilterIterator * @author Marcus Boerger - * @date 2003 - 2006 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/**
- * @brief Iterator to filter parents
- * @author Marcus Boerger
- * @version 1.2
- * @since PHP 5.1
- *
- * This extended FilterIterator allows a recursive iteration using
- * RecursiveIteratorIterator that only shows those elements which have
- * children.
- */
-class ParentIterator extends RecursiveFilterIterator
-{
- /** @return whetehr the current element has children
- */
- function accept()
- {
- return $this->it->hasChildren();
- }
-}
-
+/** + * @brief Iterator to filter parents + * @author Marcus Boerger + * @version 1.2 + * @since PHP 5.1 + * + * This extended FilterIterator allows a recursive iteration using + * RecursiveIteratorIterator that only shows those elements which have + * children. + */ +class ParentIterator extends RecursiveFilterIterator +{ + /** @return whetehr the current element has children + */ + function accept() + { + return $this->it->hasChildren(); + } +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/recursivearrayiterator.inc b/ext/spl/internal/recursivearrayiterator.inc index 833a65686..a9450e12a 100755 --- a/ext/spl/internal/recursivearrayiterator.inc +++ b/ext/spl/internal/recursivearrayiterator.inc @@ -1,59 +1,59 @@ -<?php
-
-/** @file recursivearrayiterator.inc
- * @ingroup Examples
- * @brief class RecursiveArrayIterator
- * @author Marcus Boerger
- * @date 2003 - 2005
- *
- * SPL - Standard PHP Library
- */
-
-/** @ingroup SPL
- * @brief A recursive array iterator
- * @author Marcus Boerger
- * @version 1.0
- * @since PHP 5.1
- *
- * Passes the RecursiveIterator interface to the inner Iterator and provides
- * the same functionality as FilterIterator. This allows you to skip parents
- * and all their childs before loading them all. You need to care about
- * function getChildren() because it may not always suit your needs. The
- * builtin behavior uses reflection to return a new instance of the exact same
- * class it is called from. That is you extend RecursiveFilterIterator and
- * getChildren() will create instance of that class. The problem is that doing
- * this does not transport any state or control information of your accept()
- * implementation to the new instance. To overcome this problem you might
- * need to overwrite getChildren(), call this implementation and pass the
- * control vaules manually.
- */
-class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator
-{
- /** @return whether the current element has children
- */
- function hasChildren()
- {
- return is_array($this->current());
- }
-
- /** @return an iterator for the current elements children
- *
- * @note the returned iterator will be of the same class as $this
- */
- function getChildren()
- {
- if ($this->current() instanceof self)
- {
- return $this->current();
- }
- if (empty($this->ref))
- {
- $this->ref = new ReflectionClass($this);
- }
- return $this->ref->newInstance($this->current());
- }
-
- private $ref;
-}
-
+<?php + +/** @file recursivearrayiterator.inc + * @ingroup Examples + * @brief class RecursiveArrayIterator + * @author Marcus Boerger + * @date 2003 - 2009 + * + * SPL - Standard PHP Library + */ + +/** @ingroup SPL + * @brief A recursive array iterator + * @author Marcus Boerger + * @version 1.0 + * @since PHP 5.1 + * + * Passes the RecursiveIterator interface to the inner Iterator and provides + * the same functionality as FilterIterator. This allows you to skip parents + * and all their childs before loading them all. You need to care about + * function getChildren() because it may not always suit your needs. The + * builtin behavior uses reflection to return a new instance of the exact same + * class it is called from. That is you extend RecursiveFilterIterator and + * getChildren() will create instance of that class. The problem is that doing + * this does not transport any state or control information of your accept() + * implementation to the new instance. To overcome this problem you might + * need to overwrite getChildren(), call this implementation and pass the + * control vaules manually. + */ +class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator +{ + /** @return whether the current element has children + */ + function hasChildren() + { + return is_array($this->current()); + } + + /** @return an iterator for the current elements children + * + * @note the returned iterator will be of the same class as $this + */ + function getChildren() + { + if ($this->current() instanceof self) + { + return $this->current(); + } + if (empty($this->ref)) + { + $this->ref = new ReflectionClass($this); + } + return $this->ref->newInstance($this->current()); + } + + private $ref; +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/recursivecachingiterator.inc b/ext/spl/internal/recursivecachingiterator.inc index 327514687..0676d435f 100755 --- a/ext/spl/internal/recursivecachingiterator.inc +++ b/ext/spl/internal/recursivecachingiterator.inc @@ -1,99 +1,99 @@ -<?php
-
+<?php + /** @file recursivecachingiterator.inc * @ingroup SPL * @brief class RecursiveCachingIterator * @author Marcus Boerger - * @date 2003 - 2005 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/**
- * @brief Cached recursive iteration over another Iterator
- * @author Marcus Boerger
- * @version 1.2
- * @since PHP 5.1
- *
- * @see CachingIterator
- */
-class RecursiveCachingIterator extends CachingIterator implements RecursiveIterator
-{
- private $hasChildren;
- private $getChildren;
-
- /** Construct from another iterator
- *
- * @param it Iterator to cache
- * @param flags Bitmask:
- * - CALL_TOSTRING (whether to call __toString() for every element)
- * - CATCH_GET_CHILD (whether to catch exceptions when trying to get childs)
- */
- function __construct(RecursiveIterator $it, $flags = self::CALL_TOSTRING)
- {
- parent::__construct($it, $flags);
- }
-
- /** Rewind Iterator
- */
- function rewind();
- {
- $this->hasChildren = false;
- $this->getChildren = NULL;
- parent::rewind();
- }
-
- /** Forward to next element if necessary then an Iterator for the Children
- * will be created.
- */
- function next()
- {
- if ($this->hasChildren = $this->it->hasChildren())
- {
- try
- {
- $child = $this->it->getChildren();
- if (!$this->ref)
- {
- $this->ref = new ReflectionClass($this);
- }
- $this->getChildren = $ref->newInstance($child, $this->flags);
- }
- catch(Exception $e)
- {
- if (!$this->flags & self::CATCH_GET_CHILD)
- {
- throw $e;
- }
- $this->hasChildren = false;
- $this->getChildren = NULL;
- }
- } else
- {
- $this->getChildren = NULL;
- }
- parent::next();
- }
-
- private $ref;
-
- /** @return whether the current element has children
- * @note The check whether the Iterator for the children can be created was
- * already executed. Hence when flag CATCH_GET_CHILD was given in
- * constructor this fucntion returns false so that getChildren does
- * not try to access those children.
- */
- function hasChildren()
- {
- return $this->hasChildren;
- }
-
- /** @return An Iterator for the children
- */
- function getChildren()
- {
- return $this->getChildren;
- }
-}
-
+/** + * @brief Cached recursive iteration over another Iterator + * @author Marcus Boerger + * @version 1.2 + * @since PHP 5.1 + * + * @see CachingIterator + */ +class RecursiveCachingIterator extends CachingIterator implements RecursiveIterator +{ + private $hasChildren; + private $getChildren; + + /** Construct from another iterator + * + * @param it Iterator to cache + * @param flags Bitmask: + * - CALL_TOSTRING (whether to call __toString() for every element) + * - CATCH_GET_CHILD (whether to catch exceptions when trying to get childs) + */ + function __construct(RecursiveIterator $it, $flags = self::CALL_TOSTRING) + { + parent::__construct($it, $flags); + } + + /** Rewind Iterator + */ + function rewind(); + { + $this->hasChildren = false; + $this->getChildren = NULL; + parent::rewind(); + } + + /** Forward to next element if necessary then an Iterator for the Children + * will be created. + */ + function next() + { + if ($this->hasChildren = $this->it->hasChildren()) + { + try + { + $child = $this->it->getChildren(); + if (!$this->ref) + { + $this->ref = new ReflectionClass($this); + } + $this->getChildren = $ref->newInstance($child, $this->flags); + } + catch(Exception $e) + { + if (!$this->flags & self::CATCH_GET_CHILD) + { + throw $e; + } + $this->hasChildren = false; + $this->getChildren = NULL; + } + } else + { + $this->getChildren = NULL; + } + parent::next(); + } + + private $ref; + + /** @return whether the current element has children + * @note The check whether the Iterator for the children can be created was + * already executed. Hence when flag CATCH_GET_CHILD was given in + * constructor this fucntion returns false so that getChildren does + * not try to access those children. + */ + function hasChildren() + { + return $this->hasChildren; + } + + /** @return An Iterator for the children + */ + function getChildren() + { + return $this->getChildren; + } +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/recursivefilteriterator.inc b/ext/spl/internal/recursivefilteriterator.inc index 0e17845e1..b089919a3 100755 --- a/ext/spl/internal/recursivefilteriterator.inc +++ b/ext/spl/internal/recursivefilteriterator.inc @@ -1,62 +1,62 @@ -<?php
-
-/** @file recursivefilteriterator.inc
- * @ingroup SPL
- * @brief class RecursiveFilterIterator
- * @author Marcus Boerger
- * @date 2003 - 2005
- *
- * SPL - Standard PHP Library
- */
-
-/** @ingroup SPL
- * @brief Iterator to filter recursive iterators
- * @author Marcus Boerger
- * @version 1.0
- * @since PHP 5.1
- *
- * Passes the RecursiveIterator interface to the inner Iterator and provides
- * the same functionality as FilterIterator. This allows you to skip parents
- * and all their childs before loading them all. You need to care about
- * function getChildren() because it may not always suit your needs. The
- * builtin behavior uses reflection to return a new instance of the exact same
- * class it is called from. That is you extend RecursiveFilterIterator and
- * getChildren() will create instance of that class. The problem is that doing
- * this does not transport any state or control information of your accept()
- * implementation to the new instance. To overcome this problem you might
- * need to overwrite getChildren(), call this implementation and pass the
- * control vaules manually.
- */
-abstract class RecursiveFilterIterator extends FilterIterator implements RecursiveIterator
-{
- /** @param $it the RecursiveIterator to filter
- */
- function __construct(RecursiveIterator $it)
- {
- parent::__construct($it);
- }
-
- /** @return whether the current element has children
- */
- function hasChildren()
- {
- return $this->getInnerIterator()->hasChildren();
- }
-
- /** @return an iterator for the current elements children
- *
- * @note the returned iterator will be of the same class as $this
- */
- function getChildren()
- {
- if (empty($this->ref))
- {
- $this->ref = new ReflectionClass($this);
- }
- return $this->ref->newInstance($this->getInnerIterator()->getChildren());
- }
-
- private $ref;
-}
-
+<?php + +/** @file recursivefilteriterator.inc + * @ingroup SPL + * @brief class RecursiveFilterIterator + * @author Marcus Boerger + * @date 2003 - 2009 + * + * SPL - Standard PHP Library + */ + +/** @ingroup SPL + * @brief Iterator to filter recursive iterators + * @author Marcus Boerger + * @version 1.0 + * @since PHP 5.1 + * + * Passes the RecursiveIterator interface to the inner Iterator and provides + * the same functionality as FilterIterator. This allows you to skip parents + * and all their childs before loading them all. You need to care about + * function getChildren() because it may not always suit your needs. The + * builtin behavior uses reflection to return a new instance of the exact same + * class it is called from. That is you extend RecursiveFilterIterator and + * getChildren() will create instance of that class. The problem is that doing + * this does not transport any state or control information of your accept() + * implementation to the new instance. To overcome this problem you might + * need to overwrite getChildren(), call this implementation and pass the + * control vaules manually. + */ +abstract class RecursiveFilterIterator extends FilterIterator implements RecursiveIterator +{ + /** @param $it the RecursiveIterator to filter + */ + function __construct(RecursiveIterator $it) + { + parent::__construct($it); + } + + /** @return whether the current element has children + */ + function hasChildren() + { + return $this->getInnerIterator()->hasChildren(); + } + + /** @return an iterator for the current elements children + * + * @note the returned iterator will be of the same class as $this + */ + function getChildren() + { + if (empty($this->ref)) + { + $this->ref = new ReflectionClass($this); + } + return $this->ref->newInstance($this->getInnerIterator()->getChildren()); + } + + private $ref; +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/recursiveiterator.inc b/ext/spl/internal/recursiveiterator.inc index 07ffad7d1..1eab3d69b 100755 --- a/ext/spl/internal/recursiveiterator.inc +++ b/ext/spl/internal/recursiveiterator.inc @@ -1,30 +1,30 @@ -<?php
-
+<?php + /** @file recursiveiterator.inc * @ingroup SPL * @brief class RecursiveIterator * @author Marcus Boerger - * @date 2003 - 2005 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/**
- * @brief Interface for recursive iteration with RecursiveIteratorIterator
- * @author Marcus Boerger
- * @version 1.0
- * @since PHP 5.0
- */
-interface RecursiveIterator extends Iterator
-{
- /** @return whether the current element has children
- */
- function hasChildren();
-
- /** @return the sub iterator for the current element
- * @note The returned object must implement RecursiveIterator.
- */
- function getChildren();
-}
-
+/** + * @brief Interface for recursive iteration with RecursiveIteratorIterator + * @author Marcus Boerger + * @version 1.0 + * @since PHP 5.0 + */ +interface RecursiveIterator extends Iterator +{ + /** @return whether the current element has children + */ + function hasChildren(); + + /** @return the sub iterator for the current element + * @note The returned object must implement RecursiveIterator. + */ + function getChildren(); +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/recursiveiteratoriterator.inc b/ext/spl/internal/recursiveiteratoriterator.inc index 8bb657317..35fa801e7 100755 --- a/ext/spl/internal/recursiveiteratoriterator.inc +++ b/ext/spl/internal/recursiveiteratoriterator.inc @@ -1,237 +1,237 @@ -<?php
-
-/** @file recursiveiteratoriterator.inc
- * @ingroup SPL
- * @brief class RecursiveIteratorIterator
- * @author Marcus Boerger
- * @date 2003 - 2005
- *
- * SPL - Standard PHP Library
- */
-
-/**
- * @brief Iterates through recursive iterators
- * @author Marcus Boerger
- * @version 1.2
- * @since PHP 5.0
- *
- * The objects of this class are created by instances of RecursiveIterator.
- * Elements of those iterators may be traversable themselves. If so these
- * sub elements are recursed into.
- */
-class RecursiveIteratorIterator implements OuterIterator
-{
- /** Mode: Only show leaves */
- const LEAVES_ONLY = 0;
- /** Mode: Show parents prior to their children */
- const SELF_FIRST = 1;
- /** Mode: Show all children prior to their parent */
- const CHILD_FIRST = 2;
-
- /** Flag: Catches exceptions during getChildren() calls and simply jumps
- * to the next element. */
- const CATCH_GET_CHILD = 0x00000002;
-
- private $ait = array();
- private $count = 0;
- private $mode = self::LEAVES_ONLY;
- private $flags = 0;
-
- /** Construct from RecursiveIterator
- *
- * @param it RecursiveIterator to iterate
- * @param mode Operation mode (one of):
- * - LEAVES_ONLY only show leaves
- * - SELF_FIRST show parents prior to their childs
- * - CHILD_FIRST show all children prior to their parent
- * @param flags Control flags, zero or any combination of the following
- * (since PHP 5.1).
- * - CATCH_GET_CHILD which catches exceptions during
- * getChildren() calls and simply jumps to the next
- * element.
- */
- function __construct(RecursiveIterator $it, $mode = self::LEAVES_ONLY, $flags = 0)
- {
- $this->ait[0] = $it;
- $this->mode = $mode;
- $this->flags = $flags;
- }
-
- /** Rewind to top iterator as set in constructor
- */
- function rewind()
- {
- while ($this->count) {
- unset($this->ait[$this->count--]);
- $this->endChildren();
- }
- $this->ait[0]->rewind();
- $this->ait[0]->recursed = false;
- callNextElement(true);
- }
-
- /** @return whether iterator is valid
- */
- function valid()
- {
- $count = $this->count;
- while ($count) {
- $it = $this->ait[$count];
- if ($it->valid()) {
- return true;
- }
- $count--;
- $this->endChildren();
- }
- return false;
- }
-
- /** @return current key
- */
- function key()
- {
- $it = $this->ait[$this->count];
- return $it->key();
- }
-
- /** @return current element
- */
- function current()
- {
- $it = $this->ait[$this->count];
- return $it->current();
- }
-
- /** Forward to next element
- */
- function next()
- {
- while ($this->count) {
- $it = $this->ait[$this->count];
- if ($it->valid()) {
- if (!$it->recursed && callHasChildren()) {
- $it->recursed = true;
- try
- {
- $sub = callGetChildren();
- }
- catch (Exception $e)
- {
- if (!($this->flags & self::CATCH_GET_CHILD))
- {
- throw $e;
- }
- $it->next();
- continue;
- }
- $sub->recursed = false;
- $sub->rewind();
- if ($sub->valid()) {
- $this->ait[++$this->count] = $sub;
- if (!$sub instanceof RecursiveIterator) {
- throw new Exception(get_class($sub).'::getChildren() must return an object that implements RecursiveIterator');
- }
- $this->beginChildren();
- return;
- }
- unset($sub);
- }
- $it->next();
- $it->recursed = false;
- if ($it->valid()) {
- return;
- }
- $it->recursed = false;
- }
- if ($this->count) {
- unset($this->ait[$this->count--]);
- $it = $this->ait[$this->count];
- $this->endChildren();
- callNextElement(false);
- }
- }
- callNextElement(true);
- }
-
- /** @return Sub Iterator at given level or if unspecified the current sub
- * Iterator
- */
- function getSubIterator($level = NULL)
- {
- if (is_null($level)) {
- $level = $this->count;
- }
- return @$this->ait[$level];
- }
-
- /**
- * @return The inner iterator
- */
- function getInnerIterator()
- {
- return $this->it;
- }
-
- /** @return Current Depth (Number of parents)
- */
- function getDepth()
- {
- return $this->level;
- }
-
- /** @return whether current sub iterators current element has children
- * @since PHP 5.1
- */
- function callHasChildren()
- {
- return $this->ait[$this->count]->hasChildren();
- }
-
- /** @return current sub iterators current children
- * @since PHP 5.1
- */
- function callGetChildren()
- {
- return $this->ait[$this->count]->getChildren();
- }
-
- /** Called right after calling getChildren() and its rewind().
- * @since PHP 5.1
- */
- function beginChildren()
- {
- }
-
- /** Called after current child iterator is invalid and right before it
- * gets destructed.
- * @since PHP 5.1
- */
- function endChildren()
- {
- }
-
- private function callNextElement($after_move)
- {
- if ($this->valid())
- {
- if ($after_move)
- {
- if (($this->mode == self::SELF_FIRST && $this->callHasChildren())
- || $this->mode == self::LEAVES_ONLY)
- $this->nextElement();
- }
- else
- {
- $this->nextElement();
- }
- }
- }
-
- /** Called when the next element is available
- */
- function nextElement()
- {
- }
-}
-
+<?php + +/** @file recursiveiteratoriterator.inc + * @ingroup SPL + * @brief class RecursiveIteratorIterator + * @author Marcus Boerger + * @date 2003 - 2009 + * + * SPL - Standard PHP Library + */ + +/** + * @brief Iterates through recursive iterators + * @author Marcus Boerger + * @version 1.2 + * @since PHP 5.0 + * + * The objects of this class are created by instances of RecursiveIterator. + * Elements of those iterators may be traversable themselves. If so these + * sub elements are recursed into. + */ +class RecursiveIteratorIterator implements OuterIterator +{ + /** Mode: Only show leaves */ + const LEAVES_ONLY = 0; + /** Mode: Show parents prior to their children */ + const SELF_FIRST = 1; + /** Mode: Show all children prior to their parent */ + const CHILD_FIRST = 2; + + /** Flag: Catches exceptions during getChildren() calls and simply jumps + * to the next element. */ + const CATCH_GET_CHILD = 0x00000002; + + private $ait = array(); + private $count = 0; + private $mode = self::LEAVES_ONLY; + private $flags = 0; + + /** Construct from RecursiveIterator + * + * @param it RecursiveIterator to iterate + * @param mode Operation mode (one of): + * - LEAVES_ONLY only show leaves + * - SELF_FIRST show parents prior to their childs + * - CHILD_FIRST show all children prior to their parent + * @param flags Control flags, zero or any combination of the following + * (since PHP 5.1). + * - CATCH_GET_CHILD which catches exceptions during + * getChildren() calls and simply jumps to the next + * element. + */ + function __construct(RecursiveIterator $it, $mode = self::LEAVES_ONLY, $flags = 0) + { + $this->ait[0] = $it; + $this->mode = $mode; + $this->flags = $flags; + } + + /** Rewind to top iterator as set in constructor + */ + function rewind() + { + while ($this->count) { + unset($this->ait[$this->count--]); + $this->endChildren(); + } + $this->ait[0]->rewind(); + $this->ait[0]->recursed = false; + callNextElement(true); + } + + /** @return whether iterator is valid + */ + function valid() + { + $count = $this->count; + while ($count) { + $it = $this->ait[$count]; + if ($it->valid()) { + return true; + } + $count--; + $this->endChildren(); + } + return false; + } + + /** @return current key + */ + function key() + { + $it = $this->ait[$this->count]; + return $it->key(); + } + + /** @return current element + */ + function current() + { + $it = $this->ait[$this->count]; + return $it->current(); + } + + /** Forward to next element + */ + function next() + { + while ($this->count) { + $it = $this->ait[$this->count]; + if ($it->valid()) { + if (!$it->recursed && callHasChildren()) { + $it->recursed = true; + try + { + $sub = callGetChildren(); + } + catch (Exception $e) + { + if (!($this->flags & self::CATCH_GET_CHILD)) + { + throw $e; + } + $it->next(); + continue; + } + $sub->recursed = false; + $sub->rewind(); + if ($sub->valid()) { + $this->ait[++$this->count] = $sub; + if (!$sub instanceof RecursiveIterator) { + throw new Exception(get_class($sub).'::getChildren() must return an object that implements RecursiveIterator'); + } + $this->beginChildren(); + return; + } + unset($sub); + } + $it->next(); + $it->recursed = false; + if ($it->valid()) { + return; + } + $it->recursed = false; + } + if ($this->count) { + unset($this->ait[$this->count--]); + $it = $this->ait[$this->count]; + $this->endChildren(); + callNextElement(false); + } + } + callNextElement(true); + } + + /** @return Sub Iterator at given level or if unspecified the current sub + * Iterator + */ + function getSubIterator($level = NULL) + { + if (is_null($level)) { + $level = $this->count; + } + return @$this->ait[$level]; + } + + /** + * @return The inner iterator + */ + function getInnerIterator() + { + return $this->it; + } + + /** @return Current Depth (Number of parents) + */ + function getDepth() + { + return $this->level; + } + + /** @return whether current sub iterators current element has children + * @since PHP 5.1 + */ + function callHasChildren() + { + return $this->ait[$this->count]->hasChildren(); + } + + /** @return current sub iterators current children + * @since PHP 5.1 + */ + function callGetChildren() + { + return $this->ait[$this->count]->getChildren(); + } + + /** Called right after calling getChildren() and its rewind(). + * @since PHP 5.1 + */ + function beginChildren() + { + } + + /** Called after current child iterator is invalid and right before it + * gets destructed. + * @since PHP 5.1 + */ + function endChildren() + { + } + + private function callNextElement($after_move) + { + if ($this->valid()) + { + if ($after_move) + { + if (($this->mode == self::SELF_FIRST && $this->callHasChildren()) + || $this->mode == self::LEAVES_ONLY) + $this->nextElement(); + } + else + { + $this->nextElement(); + } + } + } + + /** Called when the next element is available + */ + function nextElement() + { + } +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/recursiveregexiterator.inc b/ext/spl/internal/recursiveregexiterator.inc index df47d6197..ffcff0ce4 100755 --- a/ext/spl/internal/recursiveregexiterator.inc +++ b/ext/spl/internal/recursiveregexiterator.inc @@ -1,61 +1,61 @@ -<?php
-
+<?php + /** @file recursiveregexiterator.inc * @ingroup SPL * @brief class RegexIterator * @author Marcus Boerger - * @date 2003 - 2006 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/**
- * @brief Recursive regular expression filter for iterators
- * @author Marcus Boerger
- * @version 1.0
- * @since PHP 5.1
- *
- * This filter iterator assumes that the inner iterator
- */
-class RecursiveRegexIterator extends RegexIterator implements RecursiveIterator
-{
- /**
- * Constructs a regular expression filter around an iterator whose
- * elemnts or keys are strings.
- *
- * @param it inner iterator
- * @param regex the regular expression to match
- * @param mode operation mode (one of self::MATCH, self::GET_MATCH,
- * self::ALL_MATCHES, self::SPLIT)
- * @param flags special flags (self::USE_KEY)
- * @param preg_flags global PREG_* flags, see preg_match(),
- * preg_match_all(), preg_split()
- */
- function __construct(RecursiveIterator $it, $regex, $mode = 0, $flags = 0, $preg_flags = 0) {
- parent::__construct($it, $regex, $mode, $flags, $preg_flags);
- }
-
- /** @return whether the current element has children
- */
- function hasChildren()
- {
- return $this->getInnerIterator()->hasChildren();
- }
-
- /** @return an iterator for the current elements children
- *
- * @note the returned iterator will be of the same class as $this
- */
- function getChildren()
- {
- if (empty($this->ref))
- {
- $this->ref = new ReflectionClass($this);
- }
- return $this->ref->newInstance($this->getInnerIterator()->getChildren());
- }
-
- private $ref;
-}
-
+/** + * @brief Recursive regular expression filter for iterators + * @author Marcus Boerger + * @version 1.0 + * @since PHP 5.1 + * + * This filter iterator assumes that the inner iterator + */ +class RecursiveRegexIterator extends RegexIterator implements RecursiveIterator +{ + /** + * Constructs a regular expression filter around an iterator whose + * elemnts or keys are strings. + * + * @param it inner iterator + * @param regex the regular expression to match + * @param mode operation mode (one of self::MATCH, self::GET_MATCH, + * self::ALL_MATCHES, self::SPLIT) + * @param flags special flags (self::USE_KEY) + * @param preg_flags global PREG_* flags, see preg_match(), + * preg_match_all(), preg_split() + */ + function __construct(RecursiveIterator $it, $regex, $mode = 0, $flags = 0, $preg_flags = 0) { + parent::__construct($it, $regex, $mode, $flags, $preg_flags); + } + + /** @return whether the current element has children + */ + function hasChildren() + { + return $this->getInnerIterator()->hasChildren(); + } + + /** @return an iterator for the current elements children + * + * @note the returned iterator will be of the same class as $this + */ + function getChildren() + { + if (empty($this->ref)) + { + $this->ref = new ReflectionClass($this); + } + return $this->ref->newInstance($this->getInnerIterator()->getChildren()); + } + + private $ref; +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/recursivetreeiterator.inc b/ext/spl/internal/recursivetreeiterator.inc index b35718ee8..dfcdc0599 100755 --- a/ext/spl/internal/recursivetreeiterator.inc +++ b/ext/spl/internal/recursivetreeiterator.inc @@ -4,7 +4,7 @@ * @ingroup SPL * @brief class RecursiveTreeIterator * @author Marcus Boerger, Johannes Schlueter - * @date 2005 + * @date 2005 - 2009 * * SPL - Standard PHP Library */ diff --git a/ext/spl/internal/regexiterator.inc b/ext/spl/internal/regexiterator.inc index 05eb4b1d9..8b4ffe9da 100755 --- a/ext/spl/internal/regexiterator.inc +++ b/ext/spl/internal/regexiterator.inc @@ -1,163 +1,163 @@ -<?php
-
+<?php + /** @file regexiterator.inc * @ingroup SPL * @brief class RegexIterator * @author Marcus Boerger - * @date 2003 - 2006 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/**
- * @brief Regular expression filter for iterators
- * @author Marcus Boerger
- * @version 1.0
- * @since PHP 5.1
- *
- * This filter iterator assumes that the inner iterator
- */
-class RegexIterator implements FilterIterator
-{
- const USE_KEY = 0x00000001; /**< If present in $flags the the key is
- used rather then the current value. */
-
- const MATCH = 0; /**< Mode: Executed a plain match only */
- const GET_MATCH = 1; /**< Mode: Return the first matche (if any) */
- const ALL_MATCHES = 2; /**< Mode: Return all matches (if any) */
- const SPLIT = 3; /**< Mode: Return the split values (if any) */
- const REPLACE = 4; /**< Mode: Replace the input key or current */
-
- private $regex; /**< the regular expression to match against */
- private $mode; /**< operation mode (one of self::MATCH,
- self::GET_MATCH, self::ALL_MATCHES, self::SPLIT) */
- private $flags; /**< special flags (self::USE_KEY) */
- private $preg_flags;/**< PREG_* flags, see preg_match(), preg_match_all(),
- preg_split() */
- private $key; /**< the value used for key() */
- private $current; /**< the value used for current() */
-
- /**
- * Constructs a regular expression filter around an iterator whose
- * elemnts or keys are strings.
- *
- * @param it inner iterator
- * @param regex the regular expression to match
- * @param mode operation mode (one of self::MATCH, self::GET_MATCH,
- * self::ALL_MATCHES, self::SPLIT)
- * @param flags special flags (self::USE_KEY)
- * @param preg_flags global PREG_* flags, see preg_match(),
- * preg_match_all(), preg_split()
- */
- function __construct(Iterator $it, $regex, $mode = 0, $flags = 0, $preg_flags = 0) {
- parent::__construct($it);
- $this->regex = $regex;
- $this->flags = $flags;
- $this->mode = $mode;
- $this->preg_flags = $preg_flags;
- }
-
- /**
- * Match current or key against regular expression using mode, flags and
- * preg_flags.
- *
- * @return whether this is a match
- *
- * @warning never call this twice for the same state
- */
- function accept()
- {
- $matches = array();
- $this->key = parent::key();
- $this->current = parent::current();
- /* note that we use $this->current, rather than calling parent::current() */
- $subject = ($this->flags & self::USE_KEY) ? $this->key : $this->current;
- switch($this->mode)
- {
- case self::MATCH:
- return preg_match($this->regex, $subject, $matches, $this->preg_flags);
-
- case self::GET_MATCH:
- $this->current = array();
- return preg_match($this->regex, $subject, $this->current, $this->preg_flags) > 0;
-
- case self::ALL_MATCHES:
- $this->current = array();
- return preg_match_all($this->regex, $subject, $this->current, $this->preg_flags) > 0;
-
- case self::SPLIT:
- $this->current = array();
- preg_split($this->regex, $subject, $this->current, $this->preg_flags) > 1;
-
- case self::REPLACE:
- $this->current = array();
- $result = preg_replace($this->regex, $this->replacement, $subject);
- if ($this->flags & self::USE_KEY)
- {
- $this->key = $result;
- }
- else
- {
- $this->current = $result;
- }
- }
- }
-
- /** @return the key after accept has been called
- */
- function key()
- {
- return $this->key;
- }
-
- /** @return the current value after accept has been called
- */
- function current()
- {
- return $this->current;
- }
-
- /** @return current operation mode
- */
- function getMode()
- {
- return $this->mode;
- }
-
- /** @param mode new operaion mode
- */
- function setMode($mode)
- {
- $this->mode = $mode;
- }
-
- /** @return current operation flags
- */
- function getFlags()
- {
- return $this->flags;
- }
-
- /** @param flags new operaion flags
- */
- function setFlags($flags)
- {
- $this->flags = $flags;
- }
-
- /** @return current PREG flags
- */
- function getPregFlags()
- {
- return $this->preg_flags;
- }
-
- /** @param preg_flags new PREG flags
- */
- function setPregFlags($preg_flags)
- {
- $this->preg_flags = $preg_flags;
- }
-}
-
-?>
\ No newline at end of file +/** + * @brief Regular expression filter for iterators + * @author Marcus Boerger + * @version 1.0 + * @since PHP 5.1 + * + * This filter iterator assumes that the inner iterator + */ +class RegexIterator extends FilterIterator +{ + const USE_KEY = 0x00000001; /**< If present in $flags the the key is + used rather then the current value. */ + + const MATCH = 0; /**< Mode: Executed a plain match only */ + const GET_MATCH = 1; /**< Mode: Return the first matche (if any) */ + const ALL_MATCHES = 2; /**< Mode: Return all matches (if any) */ + const SPLIT = 3; /**< Mode: Return the split values (if any) */ + const REPLACE = 4; /**< Mode: Replace the input key or current */ + + private $regex; /**< the regular expression to match against */ + private $mode; /**< operation mode (one of self::MATCH, + self::GET_MATCH, self::ALL_MATCHES, self::SPLIT) */ + private $flags; /**< special flags (self::USE_KEY) */ + private $preg_flags;/**< PREG_* flags, see preg_match(), preg_match_all(), + preg_split() */ + private $key; /**< the value used for key() */ + private $current; /**< the value used for current() */ + + /** + * Constructs a regular expression filter around an iterator whose + * elemnts or keys are strings. + * + * @param it inner iterator + * @param regex the regular expression to match + * @param mode operation mode (one of self::MATCH, self::GET_MATCH, + * self::ALL_MATCHES, self::SPLIT) + * @param flags special flags (self::USE_KEY) + * @param preg_flags global PREG_* flags, see preg_match(), + * preg_match_all(), preg_split() + */ + function __construct(Iterator $it, $regex, $mode = 0, $flags = 0, $preg_flags = 0) { + parent::__construct($it); + $this->regex = $regex; + $this->flags = $flags; + $this->mode = $mode; + $this->preg_flags = $preg_flags; + } + + /** + * Match current or key against regular expression using mode, flags and + * preg_flags. + * + * @return whether this is a match + * + * @warning never call this twice for the same state + */ + function accept() + { + $matches = array(); + $this->key = parent::key(); + $this->current = parent::current(); + /* note that we use $this->current, rather than calling parent::current() */ + $subject = ($this->flags & self::USE_KEY) ? $this->key : $this->current; + switch($this->mode) + { + case self::MATCH: + return preg_match($this->regex, $subject, $matches, $this->preg_flags); + + case self::GET_MATCH: + $this->current = array(); + return preg_match($this->regex, $subject, $this->current, $this->preg_flags) > 0; + + case self::ALL_MATCHES: + $this->current = array(); + return preg_match_all($this->regex, $subject, $this->current, $this->preg_flags) > 0; + + case self::SPLIT: + $this->current = array(); + preg_split($this->regex, $subject, $this->current, $this->preg_flags) > 1; + + case self::REPLACE: + $this->current = array(); + $result = preg_replace($this->regex, $this->replacement, $subject); + if ($this->flags & self::USE_KEY) + { + $this->key = $result; + } + else + { + $this->current = $result; + } + } + } + + /** @return the key after accept has been called + */ + function key() + { + return $this->key; + } + + /** @return the current value after accept has been called + */ + function current() + { + return $this->current; + } + + /** @return current operation mode + */ + function getMode() + { + return $this->mode; + } + + /** @param mode new operaion mode + */ + function setMode($mode) + { + $this->mode = $mode; + } + + /** @return current operation flags + */ + function getFlags() + { + return $this->flags; + } + + /** @param flags new operaion flags + */ + function setFlags($flags) + { + $this->flags = $flags; + } + + /** @return current PREG flags + */ + function getPregFlags() + { + return $this->preg_flags; + } + + /** @param preg_flags new PREG flags + */ + function setPregFlags($preg_flags) + { + $this->preg_flags = $preg_flags; + } +} + +?> diff --git a/ext/spl/internal/seekableiterator.inc b/ext/spl/internal/seekableiterator.inc index 5ab6b9b4d..b4f66bde4 100755 --- a/ext/spl/internal/seekableiterator.inc +++ b/ext/spl/internal/seekableiterator.inc @@ -1,48 +1,48 @@ -<?php
-
+<?php + /** @file seekableiterator.inc * @ingroup SPL * @brief class SeekableIterator * @author Marcus Boerger - * @date 2003 - 2005 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/** @brief seekable iterator
- * @author Marcus Boerger
- * @version 1.0
- * @since PHP 5.0
- *
- * Turns a normal iterator ino a seekable iterator. When there is a way
- * to seek on an iterator LimitIterator can use this to efficiently rewind
- * to offset.
- */
-interface SeekableIterator extends Iterator
-{
- /** Seek to an absolute position
- *
- * \param $index position to seek to
- * \return void
- *
- * The method should throw an exception if it is not possible to seek to
- * the given position. Typically this exception should be of type
- * OutOfBoundsException.
- \code
- function seek($index);
- $this->rewind();
- $position = 0;
- while($position < $index && $this->valid()) {
- $this->next();
- $position++;
- }
- if (!$this->valid()) {
- throw new OutOfBoundsException('Invalid seek position');
- }
- }
- \endcode
- */
- function seek($index);
-}
-
+/** @brief seekable iterator + * @author Marcus Boerger + * @version 1.0 + * @since PHP 5.0 + * + * Turns a normal iterator ino a seekable iterator. When there is a way + * to seek on an iterator LimitIterator can use this to efficiently rewind + * to offset. + */ +interface SeekableIterator extends Iterator +{ + /** Seek to an absolute position + * + * \param $index position to seek to + * \return void + * + * The method should throw an exception if it is not possible to seek to + * the given position. Typically this exception should be of type + * OutOfBoundsException. + \code + function seek($index); + $this->rewind(); + $position = 0; + while($position < $index && $this->valid()) { + $this->next(); + $position++; + } + if (!$this->valid()) { + throw new OutOfBoundsException('Invalid seek position'); + } + } + \endcode + */ + function seek($index); +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/spldoublylinkedlist.inc b/ext/spl/internal/spldoublylinkedlist.inc index ba6443edc..e87e4b11d 100644 --- a/ext/spl/internal/spldoublylinkedlist.inc +++ b/ext/spl/internal/spldoublylinkedlist.inc @@ -3,7 +3,7 @@ * @ingroup SPL * @brief class SplDoublyLinkedList * @author Etienne Kneuss - * @date 2008 + * @date 2008 - 2009 * * SPL - Standard PHP Library */ diff --git a/ext/spl/internal/splfileobject.inc b/ext/spl/internal/splfileobject.inc index b78c71889..46b941f69 100755 --- a/ext/spl/internal/splfileobject.inc +++ b/ext/spl/internal/splfileobject.inc @@ -1,377 +1,377 @@ -<?php
-
-/** @file splfileobject.inc
- * @ingroup SPL
- * @brief class FileObject
- * @author Marcus Boerger
- * @date 2003 - 2006
- *
- * SPL - Standard PHP Library
- */
-
-/** @ingroup SPL
- * @brief Object representation for any stream
- * @author Marcus Boerger
- * @version 1.1
- * @since PHP 5.1
- */
-class SplFileObject extends SplFileInfo implements RecursiveIterator, SeekableIterator
-{
- /** Flag: wheter to suppress new lines */
- const DROP_NEW_LINE = 0x00000001;
-
- private $fp;
- private $fname;
- private $line = NULL;
- private $lnum = 0;
- private $max_len = 0;
- private $flags = 0;
- private $delimiter= ',';
- private $enclosure= '"';
-
- /**
- * Constructs a new file object
- *
- * @param $file_name The name of the stream to open
- * @param $open_mode The file open mode
- * @param $use_include_path Whether to search in include paths
- * @param $context A stream context
- * @throw RuntimeException If file cannot be opened (e.g. insufficient
- * access rights).
- */
- function __construct($file_name, $open_mode = 'r', $use_include_path = false, $context = NULL)
- {
- $this->fp = fopen($file_name, $open_mode, $use_include_path, $context);
- if (!$this->fp)
- {
- throw new RuntimeException("Cannot open file $file_name");
- }
- $this->fname = $file_name;
- }
-
- /**
- * @return whether the end of the stream is reached
- */
- function eof()
- {
- return eof($this->fp);
- }
-
- /** increase current line number
- * @return next line from stream
- */
- function fgets()
- {
- $this->freeLine();
- $this->lnum++;
- $buf = fgets($this->fp, $this->max_len);
-
- return $buf;
- }
-
- /**
- * @param delimiter character used as field separator
- * @param enclosure end of
- * @return array containing read data
- */
- function fgetcsv($delimiter = NULL, $enclosure = NULL)
- {
- $this->freeLine();
- $this->lnum++;
- switch(fun_num_args())
- {
- case 0:
- $delimiter = $this->delimiter;
- case 1:
- $enclosure = $this->enclosure;
- default:
- case 2:
- break;
- }
- return fgetcsv($this->fp, $this->max_len, $delimiter, $enclosure);
- }
-
- /**
- * Set the delimiter and enclosure character used in fgetcsv
- *
- * @param delimiter new delimiter, defaults to ','
- * @param enclosure new enclosure, defaults to '"'
- */
- function setCsvControl($delimiter = ';', $enclosure = '"')
- {
- $this->delimiter = $delimiter;
- $this->enclosure = $enclosure;
- }
-
- /**
- * @return array(delimiter, enclosure) as used in fgetcsv
- */
- function getCsvControl($delimiter = ',', $enclosure = '"')
- {
- return array($this->delimiter, $this->enclosure);
- }
-
- /**
- * @param operation lock operation (LOCK_SH, LOCK_EX, LOCK_UN, LOCK_NB)
- * @retval $wouldblock whether the operation would block
- */
- function flock($operation, &$wouldblock)
- {
- return flock($this->fp, $operation, $wouldblock);
- }
-
- /**
- * Flush current data
- * @return success or failure
- */
- function fflush()
- {
- return fflush($this->fp);
- }
-
- /**
- * @return current file position
- */
- function ftell()
- {
- return ftell($this->fp);
- }
-
- /**
- * @param pos new file position
- * @param whence seek method (SEEK_SET, SEEK_CUR, SEEK_END)
- * @return Upon success, returns 0; otherwise, returns -1. Note that
- * seeking past EOF is not considered an error.
- */
- function fseek($pos, $whence = SEEK_SET)
- {
- return fseek($this->fp, $pos, $whence);
- }
-
- /**
- * @return next char from file
- * @note a new line character does not increase $this->lnum
- */
- function fgetc()
- {
- $this->freeLine();
- $c = fgetc($this->fp);
- if ($c == '\n') {
- $this->lnum++;
- }
- }
-
- /** Read and return remaining part of stream
- * @return size of remaining part passed through
- */
- function fpassthru()
- {
- return fpassthru($this->fp);
- }
-
- /** Get a line from the file and strip HTML tags
- * @param $allowable_tags tags to keep in the string
- */
- function fgetss($allowable_tags = NULL)
- {
- return fgetss($this->fp, $allowable_tags);
- }
-
- /** Scan the next line
- * @param $format string specifying format to parse
- */
- function fscanf($format /* , ... */)
- {
- $this->freeLine();
- $this->lnum++;
- return fscanf($this->fp, $format /* , ... */);
- }
-
- /**
- * @param $str to write
- * @param $length maximum line length to write
- */
- function fwrite($str, $length = NULL)
- {
- return fwrite($this->fp, $length);
- }
-
- /**
- * @return array of file stat information
- */
- function fstat()
- {
- return fstat($this->fp);
- }
-
- /**
- * @param $size new size to truncate file to
- */
- function ftruncate($size)
- {
- return ftruncate($this->fp, $size);
- }
-
- /**
- * @param $flags new flag set
- */
- function setFlags($flags)
- {
- $this->flags = $flags;
- }
-
- /**
- * @return current set of flags
- */
- function getFlags()
- {
- return $this->flags;
- }
-
- /**
- * @param $max_len set the maximum line length read
- */
- function setMaxLineLen($max_len)
- {
- $this->max_len = $max_len;
- }
-
- /**
- * @return current setting for max line
- */
- function getMaxLineLen()
- {
- return $this->max_len;
- }
-
- /**
- * @return false
- */
- function hasChildren()
- {
- return false;
- }
-
- /**
- * @return false
- */
- function getChildren()
- {
- return NULL;
- }
-
- /**
- * Invalidate current line buffer and set line number to 0.
- */
- function rewind()
- {
- $this->freeLine();
- $this->lnum = 0;
- }
-
- /**
- * @return whether more data can be read
- */
- function valid()
- {
- return !$this->eof();
- }
-
- /**
- * @note Fill current line buffer if not done yet.
- * @return line buffer
- */
- function current()
- {
- if (is_null($this->line))
- {
- $this->line = getCurrentLine();
- }
- return $this->line;
- }
-
- /**
- * @return line number
- * @note fgetc() will increase the line number when reaing a new line char.
- * This has the effect key() called on a read a new line will already
- * return the increased line number.
- * @note Line counting works as long as you only read the file and do not
- * use fseek().
- */
- function key()
- {
- return $this->lnum;
- }
-
- /** Invalidate current line buffer.
- */
- function next()
- {
- $this->freeLine();
- }
-
- /**
- * @return next line read from file and increase the line counter
- */
- private function readLine()
- {
- if ($this->eof())
- {
- $this->freeLine();
- throw new RuntimeException("Cannot read from file " . $this->fname);
- }
- if ($this->line) {
- $this->lnum++;
- }
- $this->freeLine();
- $this->line = fgets($this->fp, $this->max_len);
- return $this->line;
- }
-
- /**
- * Free the current line buffer and increment the line counter
- */
- private function freeLine()
- {
- if ($this->line) {
- $this->line = NULL;
- }
- }
-
- /*
- * @note If you DO overload this function key() and current() will increment
- * $this->lnum automatically. If not then function reaLine() will do
- * that for you.
- */
- function getCurrentLine()
- {
- $this->freeLine();
- if ($this->eof())
- {
- throw new RuntimeException("Cannot read from file " . $this->fname);
- }
- $this->readLine();
- }
-
- /**
- * @return current line
- */
- function __toString()
- {
- return current();
- }
-
- /**
- * @param $line_pos Seek to this line
- */
- function seek($line_pos)
- {
- $this->rewind();
- while($this->lnum < $line_pos && !$this->eof())
- {
- $this->getCurrentLine();
- }
- }
-}
-
-?>
+<?php + +/** @file splfileobject.inc + * @ingroup SPL + * @brief class FileObject + * @author Marcus Boerger + * @date 2003 - 2009 + * + * SPL - Standard PHP Library + */ + +/** @ingroup SPL + * @brief Object representation for any stream + * @author Marcus Boerger + * @version 1.1 + * @since PHP 5.1 + */ +class SplFileObject extends SplFileInfo implements RecursiveIterator, SeekableIterator +{ + /** Flag: wheter to suppress new lines */ + const DROP_NEW_LINE = 0x00000001; + + private $fp; + private $fname; + private $line = NULL; + private $lnum = 0; + private $max_len = 0; + private $flags = 0; + private $delimiter= ','; + private $enclosure= '"'; + + /** + * Constructs a new file object + * + * @param $file_name The name of the stream to open + * @param $open_mode The file open mode + * @param $use_include_path Whether to search in include paths + * @param $context A stream context + * @throw RuntimeException If file cannot be opened (e.g. insufficient + * access rights). + */ + function __construct($file_name, $open_mode = 'r', $use_include_path = false, $context = NULL) + { + $this->fp = fopen($file_name, $open_mode, $use_include_path, $context); + if (!$this->fp) + { + throw new RuntimeException("Cannot open file $file_name"); + } + $this->fname = $file_name; + } + + /** + * @return whether the end of the stream is reached + */ + function eof() + { + return eof($this->fp); + } + + /** increase current line number + * @return next line from stream + */ + function fgets() + { + $this->freeLine(); + $this->lnum++; + $buf = fgets($this->fp, $this->max_len); + + return $buf; + } + + /** + * @param delimiter character used as field separator + * @param enclosure end of + * @return array containing read data + */ + function fgetcsv($delimiter = NULL, $enclosure = NULL) + { + $this->freeLine(); + $this->lnum++; + switch(fun_num_args()) + { + case 0: + $delimiter = $this->delimiter; + case 1: + $enclosure = $this->enclosure; + default: + case 2: + break; + } + return fgetcsv($this->fp, $this->max_len, $delimiter, $enclosure); + } + + /** + * Set the delimiter and enclosure character used in fgetcsv + * + * @param delimiter new delimiter, defaults to ',' + * @param enclosure new enclosure, defaults to '"' + */ + function setCsvControl($delimiter = ';', $enclosure = '"') + { + $this->delimiter = $delimiter; + $this->enclosure = $enclosure; + } + + /** + * @return array(delimiter, enclosure) as used in fgetcsv + */ + function getCsvControl($delimiter = ',', $enclosure = '"') + { + return array($this->delimiter, $this->enclosure); + } + + /** + * @param operation lock operation (LOCK_SH, LOCK_EX, LOCK_UN, LOCK_NB) + * @retval $wouldblock whether the operation would block + */ + function flock($operation, &$wouldblock) + { + return flock($this->fp, $operation, $wouldblock); + } + + /** + * Flush current data + * @return success or failure + */ + function fflush() + { + return fflush($this->fp); + } + + /** + * @return current file position + */ + function ftell() + { + return ftell($this->fp); + } + + /** + * @param pos new file position + * @param whence seek method (SEEK_SET, SEEK_CUR, SEEK_END) + * @return Upon success, returns 0; otherwise, returns -1. Note that + * seeking past EOF is not considered an error. + */ + function fseek($pos, $whence = SEEK_SET) + { + return fseek($this->fp, $pos, $whence); + } + + /** + * @return next char from file + * @note a new line character does not increase $this->lnum + */ + function fgetc() + { + $this->freeLine(); + $c = fgetc($this->fp); + if ($c == '\n') { + $this->lnum++; + } + } + + /** Read and return remaining part of stream + * @return size of remaining part passed through + */ + function fpassthru() + { + return fpassthru($this->fp); + } + + /** Get a line from the file and strip HTML tags + * @param $allowable_tags tags to keep in the string + */ + function fgetss($allowable_tags = NULL) + { + return fgetss($this->fp, $allowable_tags); + } + + /** Scan the next line + * @param $format string specifying format to parse + */ + function fscanf($format /* , ... */) + { + $this->freeLine(); + $this->lnum++; + return fscanf($this->fp, $format /* , ... */); + } + + /** + * @param $str to write + * @param $length maximum line length to write + */ + function fwrite($str, $length = NULL) + { + return fwrite($this->fp, $length); + } + + /** + * @return array of file stat information + */ + function fstat() + { + return fstat($this->fp); + } + + /** + * @param $size new size to truncate file to + */ + function ftruncate($size) + { + return ftruncate($this->fp, $size); + } + + /** + * @param $flags new flag set + */ + function setFlags($flags) + { + $this->flags = $flags; + } + + /** + * @return current set of flags + */ + function getFlags() + { + return $this->flags; + } + + /** + * @param $max_len set the maximum line length read + */ + function setMaxLineLen($max_len) + { + $this->max_len = $max_len; + } + + /** + * @return current setting for max line + */ + function getMaxLineLen() + { + return $this->max_len; + } + + /** + * @return false + */ + function hasChildren() + { + return false; + } + + /** + * @return false + */ + function getChildren() + { + return NULL; + } + + /** + * Invalidate current line buffer and set line number to 0. + */ + function rewind() + { + $this->freeLine(); + $this->lnum = 0; + } + + /** + * @return whether more data can be read + */ + function valid() + { + return !$this->eof(); + } + + /** + * @note Fill current line buffer if not done yet. + * @return line buffer + */ + function current() + { + if (is_null($this->line)) + { + $this->line = getCurrentLine(); + } + return $this->line; + } + + /** + * @return line number + * @note fgetc() will increase the line number when reaing a new line char. + * This has the effect key() called on a read a new line will already + * return the increased line number. + * @note Line counting works as long as you only read the file and do not + * use fseek(). + */ + function key() + { + return $this->lnum; + } + + /** Invalidate current line buffer. + */ + function next() + { + $this->freeLine(); + } + + /** + * @return next line read from file and increase the line counter + */ + private function readLine() + { + if ($this->eof()) + { + $this->freeLine(); + throw new RuntimeException("Cannot read from file " . $this->fname); + } + if ($this->line) { + $this->lnum++; + } + $this->freeLine(); + $this->line = fgets($this->fp, $this->max_len); + return $this->line; + } + + /** + * Free the current line buffer and increment the line counter + */ + private function freeLine() + { + if ($this->line) { + $this->line = NULL; + } + } + + /* + * @note If you DO overload this function key() and current() will increment + * $this->lnum automatically. If not then function reaLine() will do + * that for you. + */ + function getCurrentLine() + { + $this->freeLine(); + if ($this->eof()) + { + throw new RuntimeException("Cannot read from file " . $this->fname); + } + $this->readLine(); + } + + /** + * @return current line + */ + function __toString() + { + return current(); + } + + /** + * @param $line_pos Seek to this line + */ + function seek($line_pos) + { + $this->rewind(); + while($this->lnum < $line_pos && !$this->eof()) + { + $this->getCurrentLine(); + } + } +} + +?> diff --git a/ext/spl/internal/splobjectstorage.inc b/ext/spl/internal/splobjectstorage.inc index 9d06a05a6..fa164066c 100755 --- a/ext/spl/internal/splobjectstorage.inc +++ b/ext/spl/internal/splobjectstorage.inc @@ -1,188 +1,188 @@ -<?php
-
+<?php + /** @file splobjectstorage.inc * @ingroup SPL * @brief class SplObjectStorage * @author Marcus Boerger - * @date 2003 - 2008 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/**
- * @brief Object storage
- * @author Marcus Boerger
- * @version 1.1
- * @since PHP 5.1.2
- *
- * This container allows to store objects uniquly without the need to compare
- * them one by one. This is only possible internally. The code represenation
- * here therefore has a complexity of O(n) while the actual implementation has
- * complexity O(1).
- */
-class SplObjectStorage implements Iterator, Countable, ArrayAccess
-{
- private $storage = array();
- private $index = 0;
-
- /** Rewind to top iterator as set in constructor
- */
- function rewind()
- {
- rewind($this->storage);
- }
-
- /** @return whether iterator is valid
- */
- function valid()
- {
- return key($this->storage) !== false;
- }
-
- /** @return current key
- */
- function key()
- {
- return $this->index;
- }
-
- /** @return current object
- */
- function current()
- {
- $element = current($this->storage);
- return $element ? $element[0] : NULL
- }
-
- /** @return get current object's associated information
- * @since 5.3.0
- */
- function getInfo()
- {
- $element = current($this->storage);
- return $element ? $element[1] : NULL
- }
-
- /** @return set current object's associated information
- * @since 5.3.0
- */
- function setInfo($inf = NULL)
- {
- if ($this->valid()) {
- $this->storage[$this->index][1] = $inf;
- }
- }
-
- /** Forward to next element
- */
- function next()
- {
- next($this->storage);
- $this->index++;
- }
-
- /** @return number of objects in storage
- */
- function count()
- {
- return count($this->storage);
- }
-
- /** @param $obj object to look for
- * @return whether $obj is contained in storage
- */
- function contains($obj)
- {
- if (is_object($obj))
- {
- foreach($this->storage as $element)
- {
- if ($object === $element[0])
- {
- return true;
- }
- }
- }
- return false;
- }
-
- /** @param $obj new object to attach to storage or object whose
- * associative information is to be replaced
- * @param $inf associative information stored along the object
- */
- function attach($obj, $inf = NULL)
- {
- if (is_object($obj) && !$this->contains($obj))
- {
- $this->storage[] = array($obj, $inf);
- }
- }
-
- /** @param $obj object to remove from storage
- */
- function detach($obj)
- {
- if (is_object($obj))
- {
- foreach($this->storage as $idx => $element)
- {
- if ($object === $element[0])
- {
- unset($this->storage[$idx]);
- $this->rewind();
- return;
- }
- }
- }
- }
-
- /** @param $obj new object to attach to storage or object whose
- * associative information is to be replaced
- * @param $inf associative information stored along the object
- * @since 5.3.0
- */
- function offsetSet($obj, $inf)
- {
- $this->attach($obj, $inf);
- }
-
- /** @param $obj Exising object to look for
- * @return associative information stored with object
- * @throw UnexpectedValueException if Object $obj is not contained in
- * storage
- * @since 5.3.0
- */
- function offsetGet($obj)
- {
- if (is_object($obj))
- {
- foreach($this->storage as $idx => $element)
- {
- if ($object === $element[0])
- {
- return $element[1];
- }
- }
- }
- throw new UnexpectedValueException('Object not found');
- }
-
- /** @param $obj Exising object to look for
- * @return associative information stored with object
- * @since 5.3.0
- */
- function offsetUnset($obj)
- {
- $this->detach($obj);
- }
-
- /** @param $obj object to look for
- * @return whether $obj is contained in storage
- */
- function offsetEsists($obj)
- {
- return $this->contains($obj);
- }
-}
-
+/** + * @brief Object storage + * @author Marcus Boerger + * @version 1.1 + * @since PHP 5.1.2 + * + * This container allows to store objects uniquly without the need to compare + * them one by one. This is only possible internally. The code represenation + * here therefore has a complexity of O(n) while the actual implementation has + * complexity O(1). + */ +class SplObjectStorage implements Iterator, Countable, ArrayAccess +{ + private $storage = array(); + private $index = 0; + + /** Rewind to top iterator as set in constructor + */ + function rewind() + { + rewind($this->storage); + } + + /** @return whether iterator is valid + */ + function valid() + { + return key($this->storage) !== false; + } + + /** @return current key + */ + function key() + { + return $this->index; + } + + /** @return current object + */ + function current() + { + $element = current($this->storage); + return $element ? $element[0] : NULL + } + + /** @return get current object's associated information + * @since 5.3.0 + */ + function getInfo() + { + $element = current($this->storage); + return $element ? $element[1] : NULL + } + + /** @return set current object's associated information + * @since 5.3.0 + */ + function setInfo($inf = NULL) + { + if ($this->valid()) { + $this->storage[$this->index][1] = $inf; + } + } + + /** Forward to next element + */ + function next() + { + next($this->storage); + $this->index++; + } + + /** @return number of objects in storage + */ + function count() + { + return count($this->storage); + } + + /** @param $obj object to look for + * @return whether $obj is contained in storage + */ + function contains($obj) + { + if (is_object($obj)) + { + foreach($this->storage as $element) + { + if ($object === $element[0]) + { + return true; + } + } + } + return false; + } + + /** @param $obj new object to attach to storage or object whose + * associative information is to be replaced + * @param $inf associative information stored along the object + */ + function attach($obj, $inf = NULL) + { + if (is_object($obj) && !$this->contains($obj)) + { + $this->storage[] = array($obj, $inf); + } + } + + /** @param $obj object to remove from storage + */ + function detach($obj) + { + if (is_object($obj)) + { + foreach($this->storage as $idx => $element) + { + if ($object === $element[0]) + { + unset($this->storage[$idx]); + $this->rewind(); + return; + } + } + } + } + + /** @param $obj new object to attach to storage or object whose + * associative information is to be replaced + * @param $inf associative information stored along the object + * @since 5.3.0 + */ + function offsetSet($obj, $inf) + { + $this->attach($obj, $inf); + } + + /** @param $obj Exising object to look for + * @return associative information stored with object + * @throw UnexpectedValueException if Object $obj is not contained in + * storage + * @since 5.3.0 + */ + function offsetGet($obj) + { + if (is_object($obj)) + { + foreach($this->storage as $idx => $element) + { + if ($object === $element[0]) + { + return $element[1]; + } + } + } + throw new UnexpectedValueException('Object not found'); + } + + /** @param $obj Exising object to look for + * @return associative information stored with object + * @since 5.3.0 + */ + function offsetUnset($obj) + { + $this->detach($obj); + } + + /** @param $obj object to look for + * @return whether $obj is contained in storage + */ + function offsetEsists($obj) + { + return $this->contains($obj); + } +} + ?> diff --git a/ext/spl/internal/splqueue.inc b/ext/spl/internal/splqueue.inc index f795eabbc..368a2597f 100644 --- a/ext/spl/internal/splqueue.inc +++ b/ext/spl/internal/splqueue.inc @@ -4,7 +4,7 @@ * @ingroup SPL * @brief class SplQueue * @author Etienne Kneuss - * @date 2008 + * @date 2008 - 2009 * * SPL - Standard PHP Library */ diff --git a/ext/spl/internal/splstack.inc b/ext/spl/internal/splstack.inc index 4d3c62bab..70b144384 100644 --- a/ext/spl/internal/splstack.inc +++ b/ext/spl/internal/splstack.inc @@ -4,7 +4,7 @@ * @ingroup SPL * @brief class SplStack * @author Etienne Kneuss - * @date 2008 + * @date 2008 - 2009 * * SPL - Standard PHP Library */ diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 264f35f06..49d3f5519 100755 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_spl.c,v 1.52.2.28.2.17.2.35 2009/01/26 11:38:03 colder Exp $ */ +/* $Id: php_spl.c,v 1.52.2.28.2.17.2.38 2009/06/13 17:30:50 cellog Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -353,6 +353,7 @@ PHP_FUNCTION(spl_autoload_extensions) typedef struct { zend_function *func_ptr; zval *obj; + zval *closure; zend_class_entry *ce; } autoload_func_info; @@ -361,6 +362,9 @@ static void autoload_func_info_dtor(autoload_func_info *alfi) if (alfi->obj) { zval_ptr_dtor(&alfi->obj); } + if (alfi->closure) { + zval_ptr_dtor(&alfi->closure); + } } /* {{{ proto void spl_autoload_call(string class_name) @@ -411,6 +415,7 @@ PHP_FUNCTION(spl_autoload_call) (ht)->pListTail->pListNext = (ht)->pListHead; \ (ht)->pListHead = (ht)->pListTail; \ (ht)->pListTail = (ht)->pListHead->pListLast; \ + (ht)->pListHead->pListNext->pListLast = (ht)->pListHead;\ (ht)->pListTail->pListNext = NULL; \ (ht)->pListHead->pListLast = NULL; @@ -488,6 +493,7 @@ PHP_FUNCTION(spl_autoload_register) RETURN_FALSE; } } + alfi.closure = NULL; alfi.ce = fcc.calling_scope; alfi.func_ptr = fcc.function_handler; obj_ptr = fcc.object_ptr; @@ -499,12 +505,27 @@ PHP_FUNCTION(spl_autoload_register) zend_str_tolower_copy(lc_name, func_name, func_name_len); efree(func_name); + if (Z_TYPE_P(zcallable) == IS_OBJECT) { + alfi.closure = zcallable; + Z_ADDREF_P(zcallable); + + lc_name = erealloc(lc_name, func_name_len + 2 + sizeof(zcallable->value.obj.handle)); + memcpy(lc_name + func_name_len, &(zcallable->value.obj.handle), + sizeof(zcallable->value.obj.handle)); + func_name_len += sizeof(zcallable->value.obj.handle); + lc_name[func_name_len] = '\0'; + } + if (SPL_G(autoload_functions) && zend_hash_exists(SPL_G(autoload_functions), (char*)lc_name, func_name_len+1)) { + if (alfi.closure) { + Z_DELREF_P(zcallable); + } goto skip; } if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { /* add object id to the hash to ensure uniqueness, for more reference look at bug #40091 */ + lc_name = erealloc(lc_name, func_name_len + 2 + sizeof(zend_object_handle)); memcpy(lc_name + func_name_len, &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_object_handle)); func_name_len += sizeof(zend_object_handle); lc_name[func_name_len] = '\0'; @@ -527,6 +548,7 @@ PHP_FUNCTION(spl_autoload_register) spl_alfi.func_ptr = spl_func_ptr; spl_alfi.obj = NULL; spl_alfi.ce = NULL; + spl_alfi.closure = NULL; zend_hash_add(SPL_G(autoload_functions), "spl_autoload", sizeof("spl_autoload"), &spl_alfi, sizeof(autoload_func_info), NULL); if (prepend && SPL_G(autoload_functions)->nNumOfElements > 1) { /* Move the newly created element to the head of the hashtable */ diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 2d348ae46..16d213129 100755 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_array.c,v 1.71.2.17.2.13.2.39 2009/03/19 03:01:37 colder Exp $ */ +/* $Id: spl_array.c,v 1.71.2.17.2.13.2.40 2009/05/21 13:26:14 lbarnaud Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -745,12 +745,12 @@ static int spl_array_has_property(zval *object, zval *member, int has_set_exists { spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - if (std_object_handlers.has_property(object, member, has_set_exists TSRMLS_CC)) { - return 1; - } else if ((intern->ar_flags & SPL_ARRAY_ARRAY_AS_PROPS) != 0) { + if ((intern->ar_flags & SPL_ARRAY_ARRAY_AS_PROPS) != 0 + && !std_object_handlers.has_property(object, member, 2 TSRMLS_CC)) { return spl_array_has_dimension(object, member, has_set_exists TSRMLS_CC); } - return 0; + return std_object_handlers.has_property(object, member, has_set_exists TSRMLS_CC); + } /* }}} */ static void spl_array_unset_property(zval *object, zval *member TSRMLS_DC) /* {{{ */ diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 3bbd1fc94..e4ee21a4b 100755 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_directory.c,v 1.45.2.27.2.23.2.41 2009/03/10 23:28:17 helly Exp $ */ +/* $Id: spl_directory.c,v 1.45.2.27.2.23.2.43 2009/06/04 14:46:26 colder Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -1216,7 +1216,7 @@ SPL_METHOD(FilesystemIterator, getFlags) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - RETURN_LONG(intern->flags & (SPL_FILE_DIR_KEY_MODE_MASK | SPL_FILE_DIR_CURRENT_MODE_MASK)); + RETURN_LONG(intern->flags & (SPL_FILE_DIR_KEY_MODE_MASK | SPL_FILE_DIR_CURRENT_MODE_MASK | SPL_FILE_DIR_OTHERS_MASK)); } /* }}} */ /* {{{ proto void FilesystemIterator::setFlags(long $flags) @@ -1228,8 +1228,8 @@ SPL_METHOD(FilesystemIterator, setFlags) zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &flags); - intern->flags &= ~(SPL_FILE_DIR_KEY_MODE_MASK|SPL_FILE_DIR_CURRENT_MODE_MASK); - intern->flags |= ((SPL_FILE_DIR_KEY_MODE_MASK|SPL_FILE_DIR_CURRENT_MODE_MASK) & flags); + intern->flags &= ~(SPL_FILE_DIR_KEY_MODE_MASK|SPL_FILE_DIR_CURRENT_MODE_MASK|SPL_FILE_DIR_OTHERS_MASK); + intern->flags |= ((SPL_FILE_DIR_KEY_MODE_MASK|SPL_FILE_DIR_CURRENT_MODE_MASK|SPL_FILE_DIR_OTHERS_MASK) & flags); } /* }}} */ /* {{{ proto bool RecursiveDirectoryIterator::hasChildren([bool $allow_links = false]) @@ -1268,24 +1268,27 @@ SPL_METHOD(RecursiveDirectoryIterator, getChildren) spl_filesystem_object_get_file_name(intern TSRMLS_CC); - INIT_PZVAL(&zflags); - INIT_PZVAL(&zpath); - ZVAL_LONG(&zflags, intern->flags); - ZVAL_STRINGL(&zpath, intern->file_name, intern->file_name_len, 0); - - spl_instantiate_arg_ex2(Z_OBJCE_P(getThis()), &return_value, 0, &zpath, &zflags TSRMLS_CC); - - subdir = (spl_filesystem_object*)zend_object_store_get_object(return_value TSRMLS_CC); - if (subdir) { - if (intern->u.dir.sub_path && intern->u.dir.sub_path[0]) { - subdir->u.dir.sub_path_len = spprintf(&subdir->u.dir.sub_path, 0, "%s%c%s", intern->u.dir.sub_path, slash, intern->u.dir.entry.d_name); - } else { - subdir->u.dir.sub_path_len = strlen(intern->u.dir.entry.d_name); - subdir->u.dir.sub_path = estrndup(intern->u.dir.entry.d_name, subdir->u.dir.sub_path_len); + if (SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_CURRENT_AS_PATHNAME)) { + RETURN_STRINGL(intern->file_name, intern->file_name_len, 1); + } else { + INIT_PZVAL(&zflags); + INIT_PZVAL(&zpath); + ZVAL_LONG(&zflags, intern->flags); + ZVAL_STRINGL(&zpath, intern->file_name, intern->file_name_len, 0); + spl_instantiate_arg_ex2(Z_OBJCE_P(getThis()), &return_value, 0, &zpath, &zflags TSRMLS_CC); + + subdir = (spl_filesystem_object*)zend_object_store_get_object(return_value TSRMLS_CC); + if (subdir) { + if (intern->u.dir.sub_path && intern->u.dir.sub_path[0]) { + subdir->u.dir.sub_path_len = spprintf(&subdir->u.dir.sub_path, 0, "%s%c%s", intern->u.dir.sub_path, slash, intern->u.dir.entry.d_name); + } else { + subdir->u.dir.sub_path_len = strlen(intern->u.dir.entry.d_name); + subdir->u.dir.sub_path = estrndup(intern->u.dir.entry.d_name, subdir->u.dir.sub_path_len); + } + subdir->info_class = intern->info_class; + subdir->file_class = intern->file_class; + subdir->oth = intern->oth; } - subdir->info_class = intern->info_class; - subdir->file_class = intern->file_class; - subdir->oth = intern->oth; } } /* }}} */ diff --git a/ext/spl/spl_directory.h b/ext/spl/spl_directory.h index 62f75dab8..9659fb545 100755 --- a/ext/spl/spl_directory.h +++ b/ext/spl/spl_directory.h @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_directory.h,v 1.12.2.5.2.4.2.13 2008/12/31 11:15:43 sebastian Exp $ */ +/* $Id: spl_directory.h,v 1.12.2.5.2.4.2.14 2009/06/04 14:46:26 colder Exp $ */ #ifndef SPL_DIRECTORY_H #define SPL_DIRECTORY_H @@ -134,6 +134,7 @@ static inline spl_filesystem_object* spl_filesystem_iterator_to_object(spl_files #define SPL_FILE_DIR_SKIPDOTS 0x00001000 /* Tells whether it should skip dots or not */ #define SPL_FILE_DIR_UNIXPATHS 0x00002000 /* Whether to unixify path separators */ +#define SPL_FILE_DIR_OTHERS_MASK 0x00003000 /* mask used for get/setFlags */ #endif /* SPL_DIRECTORY_H */ diff --git a/ext/spl/spl_dllist.c b/ext/spl/spl_dllist.c index a4493408f..9d6a9a8ff 100644 --- a/ext/spl/spl_dllist.c +++ b/ext/spl/spl_dllist.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_dllist.c,v 1.1.2.18 2008/12/31 11:15:43 sebastian Exp $ */ +/* $Id: spl_dllist.c,v 1.1.2.19 2009/06/17 13:27:09 scottmac Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -348,6 +348,7 @@ static void spl_dllist_object_free_storage(void *object TSRMLS_DC) /* {{{ */ } spl_ptr_llist_destroy(intern->llist TSRMLS_CC); + SPL_LLIST_CHECK_DELREF(intern->traverse_pointer); zval_ptr_dtor(&intern->retval); efree(object); @@ -1036,6 +1037,16 @@ SPL_METHOD(SplDoublyLinkedList, key) } /* }}} */ +/* {{{ proto void SplDoublyLinkedList::prev() U + Move to next entry */ +SPL_METHOD(SplDoublyLinkedList, prev) +{ + spl_dllist_object *intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC); + + spl_dllist_it_helper_move_forward(&intern->traverse_pointer, &intern->traverse_position, intern->llist, intern->flags ^ SPL_DLLIST_IT_LIFO TSRMLS_CC); +} +/* }}} */ + /* {{{ proto void SplDoublyLinkedList::next() U Move to next entry */ SPL_METHOD(SplDoublyLinkedList, next) @@ -1164,6 +1175,7 @@ static const zend_function_entry spl_funcs_SplDoublyLinkedList[] = { SPL_ME(SplDoublyLinkedList, current, NULL, ZEND_ACC_PUBLIC) SPL_ME(SplDoublyLinkedList, key, NULL, ZEND_ACC_PUBLIC) SPL_ME(SplDoublyLinkedList, next, NULL, ZEND_ACC_PUBLIC) + SPL_ME(SplDoublyLinkedList, prev, NULL, ZEND_ACC_PUBLIC) SPL_ME(SplDoublyLinkedList, valid, NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index e4fa58633..5576fd397 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_fixedarray.c,v 1.1.2.10 2008/12/31 11:15:43 sebastian Exp $ */ +/* $Id: spl_fixedarray.c,v 1.1.2.11 2009/05/23 15:14:15 felipe Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -912,6 +912,10 @@ static void spl_fixedarray_it_move_forward(zend_object_iterator *iter TSRMLS_DC) SPL_METHOD(SplFixedArray, key) { spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + return; + } RETURN_LONG(intern->current); } @@ -922,6 +926,10 @@ SPL_METHOD(SplFixedArray, key) SPL_METHOD(SplFixedArray, next) { spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + return; + } intern->current++; } @@ -932,6 +940,10 @@ SPL_METHOD(SplFixedArray, next) SPL_METHOD(SplFixedArray, valid) { spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + return; + } RETURN_BOOL(intern->current >= 0 && intern->array && intern->current < intern->array->size); } @@ -942,6 +954,10 @@ SPL_METHOD(SplFixedArray, valid) SPL_METHOD(SplFixedArray, rewind) { spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + return; + } intern->current = 0; } @@ -953,7 +969,10 @@ SPL_METHOD(SplFixedArray, current) { zval *zindex, **value_pp; spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + + if (zend_parse_parameters_none() == FAILURE) { + return; + } ALLOC_INIT_ZVAL(zindex); ZVAL_LONG(zindex, intern->current); diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 2c5032cf8..11aa01911 100755 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_iterators.c,v 1.73.2.30.2.28.2.22 2009/01/20 00:43:25 felipe Exp $ */ +/* $Id: spl_iterators.c,v 1.73.2.30.2.28.2.24 2009/05/09 19:45:26 scottmac Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -596,7 +596,9 @@ SPL_METHOD(RecursiveIteratorIterator, current) zval **data; iterator->funcs->get_current_data(iterator, &data TSRMLS_CC); - RETURN_ZVAL(*data, 1, 0); + if (data && *data) { + RETURN_ZVAL(*data, 1, 0); + } } /* }}} */ /* {{{ proto void RecursiveIteratorIterator::next() @@ -922,7 +924,9 @@ static void spl_recursive_tree_iterator_get_entry(spl_recursive_it_object * obje iterator->funcs->get_current_data(iterator, &data TSRMLS_CC); zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling TSRMLS_CC); - RETVAL_ZVAL(*data, 1, 0); + if (data && *data) { + RETVAL_ZVAL(*data, 1, 0); + } if (Z_TYPE_P(return_value) == IS_ARRAY) { zval_dtor(return_value); ZVAL_STRINGL(return_value, "Array", sizeof("Array")-1, 1); @@ -1006,7 +1010,11 @@ SPL_METHOD(RecursiveTreeIterator, current) zval **data; iterator->funcs->get_current_data(iterator, &data TSRMLS_CC); - RETURN_ZVAL(*data, 1, 0); + if (data && *data) { + RETURN_ZVAL(*data, 1, 0); + } else { + RETURN_NULL(); + } } spl_recursive_tree_iterator_get_prefix(object, &prefix TSRMLS_CC); @@ -2729,7 +2737,9 @@ SPL_METHOD(NoRewindIterator, current) intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); intern->inner.iterator->funcs->get_current_data(intern->inner.iterator, &data TSRMLS_CC); - RETURN_ZVAL(*data, 1, 0); + if (data && *data) { + RETURN_ZVAL(*data, 1, 0); + } } /* }}} */ /* {{{ proto void NoRewindIterator::next() @@ -3041,6 +3051,9 @@ static int spl_iterator_to_array_apply(zend_object_iterator *iter, void *puser T if (EG(exception)) { return ZEND_HASH_APPLY_STOP; } + if (data == NULL || *data == NULL) { + return ZEND_HASH_APPLY_STOP; + } if (iter->funcs->get_current_key) { key_type = iter->funcs->get_current_key(iter, &str_key, &str_key_len, &int_key TSRMLS_CC); if (EG(exception)) { @@ -3072,6 +3085,9 @@ static int spl_iterator_to_values_apply(zend_object_iterator *iter, void *puser if (EG(exception)) { return ZEND_HASH_APPLY_STOP; } + if (data == NULL || *data == NULL) { + return ZEND_HASH_APPLY_STOP; + } Z_ADDREF_PP(data); add_next_index_zval(return_value, *data); return ZEND_HASH_APPLY_KEEP; diff --git a/ext/spl/tests/DirectoryIterator_getBasename_basic_test.phpt b/ext/spl/tests/DirectoryIterator_getBasename_basic_test.phpt new file mode 100644 index 000000000..f748bb1c9 --- /dev/null +++ b/ext/spl/tests/DirectoryIterator_getBasename_basic_test.phpt @@ -0,0 +1,23 @@ +--TEST--
+DirectoryIterator::getBasename() - Basic Test
+--CREDITS--
+PHPNW Testfest 2009 - Adrian Hardy
+--FILE--
+<?php
+ $targetDir = __DIR__.DIRECTORY_SEPARATOR.md5('directoryIterator::getbasename');
+ mkdir($targetDir);
+ touch($targetDir.DIRECTORY_SEPARATOR.'getBasename_test.txt');
+ $dir = new DirectoryIterator($targetDir.DIRECTORY_SEPARATOR);
+ while(!$dir->isFile()) {
+ $dir->next();
+ }
+ echo $dir->getBasename('.txt');
+?>
+--CLEAN--
+<?php
+ $targetDir = __DIR__.DIRECTORY_SEPARATOR.md5('directoryIterator::getbasename');
+ unlink($targetDir.DIRECTORY_SEPARATOR.'getBasename_test.txt');
+ rmdir($targetDir);
+?>
+--EXPECTF--
+getBasename_test
diff --git a/ext/spl/tests/DirectoryIterator_getBasename_pass_array.phpt b/ext/spl/tests/DirectoryIterator_getBasename_pass_array.phpt new file mode 100644 index 000000000..cad30c686 --- /dev/null +++ b/ext/spl/tests/DirectoryIterator_getBasename_pass_array.phpt @@ -0,0 +1,23 @@ +--TEST--
+DirectoryIterator::getBasename() - Pass unexpected array
+--CREDITS--
+PHPNW Testfest 2009 - Adrian Hardy
+--FILE--
+<?php
+ $targetDir = __DIR__.DIRECTORY_SEPARATOR.md5('directoryIterator::getbasename');
+ mkdir($targetDir);
+ touch($targetDir.DIRECTORY_SEPARATOR.'getBasename_test.txt');
+ $dir = new DirectoryIterator($targetDir.DIRECTORY_SEPARATOR);
+ while(!$dir->isFile()) {
+ $dir->next();
+ }
+ echo $dir->getBasename(array());
+?>
+--CLEAN--
+<?php
+ $targetDir = __DIR__.DIRECTORY_SEPARATOR.md5('directoryIterator::getbasename');
+ unlink($targetDir.DIRECTORY_SEPARATOR.'getBasename_test.txt');
+ rmdir($targetDir);
+?>
+--EXPECTF--
+Warning: DirectoryIterator::getBasename() expects parameter 1 to be %binary_string_optional%, array given in %s on line %d
diff --git a/ext/spl/tests/SplArray_fromArray.phpt b/ext/spl/tests/SplArray_fromArray.phpt new file mode 100644 index 000000000..1144f5f8d --- /dev/null +++ b/ext/spl/tests/SplArray_fromArray.phpt @@ -0,0 +1,17 @@ +--TEST-- +Check that SplArray::fromArray will not allow integer overflows +--CREDITS-- +Rob Knight <themanhimself@robknight.org.uk> PHPNW Test Fest 2009 +--FILE-- +<?php +$array = array(PHP_INT_MAX => 'foo'); +$splArray = new SplFixedArray(); + +try { + $splArray->fromArray($array); +} catch (Exception $e) { + echo $e->getMessage(); +} +?> +--EXPECT-- +integer overflow detected
\ No newline at end of file diff --git a/ext/spl/tests/SplDoublyLinkedList_bottom_pass_array.phpt b/ext/spl/tests/SplDoublyLinkedList_bottom_pass_array.phpt new file mode 100644 index 000000000..4891fbedd --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_bottom_pass_array.phpt @@ -0,0 +1,14 @@ +--TEST--
+SplDoublyLinkedList::bottom() - pass in an unexpected array parameter
+--CREDITS--
+PHPNW Testfest 2009 - Adrian Hardy
+--FILE--
+<?php
+
+$list = new SplDoublyLinkedList();
+$list->push("top");
+$list->bottom(array());
+
+?>
+--EXPECTF--
+Warning: SplDoublyLinkedList::bottom() expects exactly 0 parameters, 1 given in %s on line %d
diff --git a/ext/spl/tests/SplDoublyLinkedList_bottom_pass_float.phpt b/ext/spl/tests/SplDoublyLinkedList_bottom_pass_float.phpt new file mode 100644 index 000000000..cff9d6a5e --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_bottom_pass_float.phpt @@ -0,0 +1,14 @@ +--TEST--
+SplDoublyLinkedList::bottom() - pass in an unexpected float parameter
+--CREDITS--
+PHPNW Testfest 2009 - Adrian Hardy
+--FILE--
+<?php
+
+$list = new SplDoublyLinkedList();
+$list->push("top");
+$list->bottom(3.14159);
+
+?>
+--EXPECTF--
+Warning: SplDoublyLinkedList::bottom() expects exactly 0 parameters, 1 given in %s on line %d
diff --git a/ext/spl/tests/SplDoublyLinkedList_bottom_pass_integer.phpt b/ext/spl/tests/SplDoublyLinkedList_bottom_pass_integer.phpt new file mode 100644 index 000000000..e966199d7 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_bottom_pass_integer.phpt @@ -0,0 +1,14 @@ +--TEST--
+SplDoublyLinkedList::bottom() - pass in an unexpected integer parameter
+--CREDITS--
+PHPNW Testfest 2009 - Adrian Hardy
+--FILE--
+<?php
+
+$list = new SplDoublyLinkedList();
+$list->push("top");
+$list->bottom(45);
+
+?>
+--EXPECTF--
+Warning: SplDoublyLinkedList::bottom() expects exactly 0 parameters, 1 given in %s on line %d
diff --git a/ext/spl/tests/SplDoublyLinkedList_bottom_pass_null.phpt b/ext/spl/tests/SplDoublyLinkedList_bottom_pass_null.phpt new file mode 100644 index 000000000..05b6be932 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_bottom_pass_null.phpt @@ -0,0 +1,14 @@ +--TEST--
+SplDoublyLinkedList::bottom() - pass in an unexpected null parameter
+--CREDITS--
+PHPNW Testfest 2009 - Adrian Hardy
+--FILE--
+<?php
+
+$list = new SplDoublyLinkedList();
+$list->push("top");
+$list->bottom(null);
+
+?>
+--EXPECTF--
+Warning: SplDoublyLinkedList::bottom() expects exactly 0 parameters, 1 given in %s on line %d
diff --git a/ext/spl/tests/SplDoublyLinkedList_count.phpt b/ext/spl/tests/SplDoublyLinkedList_count.phpt new file mode 100644 index 000000000..72b029cce --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_count.phpt @@ -0,0 +1,12 @@ +--TEST-- +Check that SplDoublyLinkedList::count fails if parameter passed in +--CREDITS-- +Rob Knight <themanhimself@robknight.org.uk> PHPNW Test Fest 2009 +--FILE-- +<?php +$list = new SplDoublyLinkedList(); + +$c = $list->count('foo'); +?> +--EXPECTF-- +Warning: SplDoublyLinkedList::count() expects exactly 0 parameters, 1 given in %s on line 4 diff --git a/ext/spl/tests/SplDoublyLinkedList_count_param_SplDoublyLinkedList.phpt b/ext/spl/tests/SplDoublyLinkedList_count_param_SplDoublyLinkedList.phpt new file mode 100644 index 000000000..77bd11ee5 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_count_param_SplDoublyLinkedList.phpt @@ -0,0 +1,11 @@ +--TEST--
+Create a SplDoublyLinkedList, call count() and pass a SplDoublyLinkedList object as the parameter.
+--CREDITS--
+Philip Norton philipnorton42@gmail.com
+--FILE--
+<?php
+$dll = new SplDoublyLinkedList(2);
+$dll->count(new SplDoublyLinkedList(2));
+?>
+--EXPECTF--
+Warning: SplDoublyLinkedList::count() expects exactly 0 parameters, 1 given in %s on line %d
\ No newline at end of file diff --git a/ext/spl/tests/SplDoublyLinkedList_current.phpt b/ext/spl/tests/SplDoublyLinkedList_current.phpt new file mode 100644 index 000000000..3e13a6b7f --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_current.phpt @@ -0,0 +1,11 @@ +--TEST-- +SplDoublyLinkedList getIteratorMode +--CREDITS-- +PHPNW Testfest 2009 - Lorna Mitchell +--FILE-- +<?php +$list = new SplDoublyLinkedList(); +var_dump($list->current()); +?> +--EXPECT-- +NULL diff --git a/ext/spl/tests/SplDoublyLinkedList_current_empty.phpt b/ext/spl/tests/SplDoublyLinkedList_current_empty.phpt new file mode 100644 index 000000000..99aaf2691 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_current_empty.phpt @@ -0,0 +1,13 @@ +--TEST--
+Run current() function on an empty SplDoublyLinkedList.
+--CREDITS--
+Philip Norton philipnorton42@gmail.com
+--FILE--
+<?php
+
+$list = new SplDoublyLinkedList();
+var_dump($list->current());
+
+?>
+--EXPECT--
+NULL
\ No newline at end of file diff --git a/ext/spl/tests/SplDoublyLinkedList_debug-info.phpt b/ext/spl/tests/SplDoublyLinkedList_debug-info.phpt new file mode 100644 index 000000000..3164b4220 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_debug-info.phpt @@ -0,0 +1,29 @@ +--TEST-- +Check that SplDoublyLinkedList returns debug info when print_r is used. +--CREDITS-- +PHPNW Testfest 2009 - Paul Court ( g@rgoyle.com ) +--FILE-- +<?php + // Create a new Doubly Linked List + $dll = new SplDoublyLinkedList(); + + // Add some items to the list + $dll->push(1); + $dll->push(2); + $dll->push(3); + + // Check the debug info + print_r($dll); +?> +--EXPECT-- +SplDoublyLinkedList Object +( + [flags:SplDoublyLinkedList:private] => 0 + [dllist:SplDoublyLinkedList:private] => Array + ( + [0] => 1 + [1] => 2 + [2] => 3 + ) + +) diff --git a/ext/spl/tests/SplDoublyLinkedList_getIteratorMode.phpt b/ext/spl/tests/SplDoublyLinkedList_getIteratorMode.phpt new file mode 100644 index 000000000..d1bfb46de --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_getIteratorMode.phpt @@ -0,0 +1,12 @@ +--TEST-- +SplDoublyLinkedList getIteratorMode +--CREDITS-- +PHPNW Testfest 2009 - Lorna Mitchell +--FILE-- +<?php +$list = new SplDoublyLinkedList(); +$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP); +echo $list->getIteratorMode(); +?> +--EXPECT-- +0 diff --git a/ext/spl/tests/SplDoublyLinkedList_getIteratorMode_error.phpt b/ext/spl/tests/SplDoublyLinkedList_getIteratorMode_error.phpt new file mode 100644 index 000000000..cb43bee1c --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_getIteratorMode_error.phpt @@ -0,0 +1,12 @@ +--TEST-- +SplDoublyLinkedList getIteratorMode with an unexpected parameter +--CREDITS-- +PHPNW Testfest 2009 - Lorna Mitchell +--FILE-- +<?php +$list = new SplDoublyLinkedList(); +$list->getIteratorMode(24); +?> +--EXPECTF-- +Warning: SplDoublyLinkedList::getIteratorMode() expects exactly 0 parameters, 1 given in %s on line %d + diff --git a/ext/spl/tests/SplDoublyLinkedList_isEmpty_empty-with-parameter.phpt b/ext/spl/tests/SplDoublyLinkedList_isEmpty_empty-with-parameter.phpt new file mode 100644 index 000000000..8d7aaf8c9 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_isEmpty_empty-with-parameter.phpt @@ -0,0 +1,14 @@ +--TEST-- +Check that SplDoublyLinkedList->isEmpty() returns an error message when a parameter is passed. +--CREDITS-- +PHPNW Testfest 2009 - Paul Court ( g@rgoyle.com ) +--FILE-- +<?php + // Create a new Doubly Linked List + $dll = new SplDoublyLinkedList(); + + var_dump($dll->isEmpty("test")); +?> +--EXPECTF-- +Warning: SplDoublyLinkedList::isEmpty() expects exactly 0 parameters, %d given in %s +NULL
\ No newline at end of file diff --git a/ext/spl/tests/SplDoublyLinkedList_isEmpty_empty.phpt b/ext/spl/tests/SplDoublyLinkedList_isEmpty_empty.phpt new file mode 100644 index 000000000..f129385d0 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_isEmpty_empty.phpt @@ -0,0 +1,13 @@ +--TEST-- +Check that SplDoublyLinkedList->isEmpty() correctly returns true for an empty list. +--CREDITS-- +PHPNW Testfest 2009 - Paul Court ( g@rgoyle.com ) +--FILE-- +<?php + // Create a new Doubly Linked List + $dll = new SplDoublyLinkedList(); + + var_dump($dll->isEmpty()); +?> +--EXPECT-- +bool(true) diff --git a/ext/spl/tests/SplDoublyLinkedList_isEmpty_not-empty-with-parameter.phpt b/ext/spl/tests/SplDoublyLinkedList_isEmpty_not-empty-with-parameter.phpt new file mode 100644 index 000000000..6ea9198bf --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_isEmpty_not-empty-with-parameter.phpt @@ -0,0 +1,20 @@ +--TEST-- +Check that SplDoublyLinkedList->isEmpty() returns an error message when a parameter is passed. +--CREDITS-- +PHPNW Testfest 2009 - Paul Court ( g@rgoyle.com ) +--FILE-- +<?php + // Create a new Doubly Linked List + $dll = new SplDoublyLinkedList(); + + // Add some items to the list + $dll->push(1); + $dll->push(2); + $dll->push(3); + //var_dump($dll); + + var_dump($dll->isEmpty("test")); +?> +--EXPECTF-- +Warning: SplDoublyLinkedList::isEmpty() expects exactly 0 parameters, %d given in %s +NULL
\ No newline at end of file diff --git a/ext/spl/tests/SplDoublyLinkedList_isEmpty_not-empty.phpt b/ext/spl/tests/SplDoublyLinkedList_isEmpty_not-empty.phpt new file mode 100644 index 000000000..cac1866bc --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_isEmpty_not-empty.phpt @@ -0,0 +1,19 @@ +--TEST-- +Check that SplDoublyLinkedList->isEmpty() correctly returns true for a non-empty list. +--CREDITS-- +PHPNW Testfest 2009 - Paul Court ( g@rgoyle.com ) +--FILE-- +<?php + // Create a new Doubly Linked List + $dll = new SplDoublyLinkedList(); + + // Add some items to the list + $dll->push(1); + $dll->push(2); + $dll->push(3); + //var_dump($dll); + + var_dump($dll->isEmpty()); +?> +--EXPECT-- +bool(false) diff --git a/ext/spl/tests/SplDoublyLinkedList_lifoMode.phpt b/ext/spl/tests/SplDoublyLinkedList_lifoMode.phpt new file mode 100644 index 000000000..86a84567a --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_lifoMode.phpt @@ -0,0 +1,23 @@ +--TEST-- +Check that SplDoublyLinkedList can traverse backwards +--CREDITS-- +Rob Knight <themanhimself@robknight.org.uk> PHPNW Test Fest 2009 +--FILE-- +<?php +$list = new SplDoublyLinkedList(); + +$list->push('o'); +$list->push('o'); +$list->push('f'); + +$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO); + +$list->rewind(); + +while ($tmp = $list->current()) { + echo $tmp; + $list->next(); +} +?> +--EXPECT-- +foo
\ No newline at end of file diff --git a/ext/spl/tests/SplDoublyLinkedList_offsetExists_invalid_parameter.phpt b/ext/spl/tests/SplDoublyLinkedList_offsetExists_invalid_parameter.phpt new file mode 100644 index 000000000..f0e1b8ba1 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_offsetExists_invalid_parameter.phpt @@ -0,0 +1,15 @@ +--TEST-- +SPL SplDoublyLinkedList offsetExists displays warning and returns null on no parameters +--CREDITS-- +PHPNW TestFest 2009 - Ben Longden +--FILE-- +<?php +$list = new SplDoublyLinkedList(); +$a = $list->offsetExists(); +if(is_null($a)) { + echo 'PASS'; +} +?> +--EXPECTF-- +Warning: SplDoublyLinkedList::offsetExists() expects exactly 1 parameter, 0 given in %s on line %d +PASS diff --git a/ext/spl/tests/SplDoublyLinkedList_offsetExists_success.phpt b/ext/spl/tests/SplDoublyLinkedList_offsetExists_success.phpt new file mode 100644 index 000000000..0399b4948 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_offsetExists_success.phpt @@ -0,0 +1,31 @@ +--TEST-- +SPL SplDoublyLinkedList offsetExists returns correct values +--CREDITS-- +PHPNW TestFest 2009 - Ben Longden +--FILE-- +<?php +$list = new SplDoublyLinkedList(); + +// Push two values onto the list +$list->push('abc'); +$list->push('def'); + +// Validate that we can see the first value +if($list->offsetExists(0) === true) { + echo "PASS\n"; +} + +// Validate that we can see the second value +if($list->offsetExists(1) === true) { + echo "PASS\n"; +} + +// Check that there is no third value +if($list->offsetExists(2) === false) { + echo "PASS\n"; +} +?> +--EXPECTF-- +PASS +PASS +PASS diff --git a/ext/spl/tests/SplDoublyLinkedList_offsetGet_empty.phpt b/ext/spl/tests/SplDoublyLinkedList_offsetGet_empty.phpt new file mode 100644 index 000000000..639e35fe0 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_offsetGet_empty.phpt @@ -0,0 +1,14 @@ +--TEST--
+SplDoublyLinkedList::offsetGet() with no parameter passed.
+--CREDITS--
+PHPNW Test Fest 2009 - Jordan Hatch
+--FILE--
+<?php
+
+$array = new SplDoublyLinkedList( );
+
+$get = $array->offsetGet();
+
+?>
+--EXPECTF--
+Warning: SplDoublyLinkedList::offsetGet() expects exactly 1 parameter, 0 given in %s on line %d
\ No newline at end of file diff --git a/ext/spl/tests/SplDoublyLinkedList_offsetGet_missing_param.phpt b/ext/spl/tests/SplDoublyLinkedList_offsetGet_missing_param.phpt new file mode 100644 index 000000000..beffe7ad8 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_offsetGet_missing_param.phpt @@ -0,0 +1,15 @@ +--TEST-- +Tests that the offsetGet() method throws an error when no argument is sent +--CREDITS-- +PHPNW Test Fest 2009 - Rick Ogden +--FILE-- +<?php +$dll = new SplDoublyLinkedList(); +$dll->push(1); +$dll->push(2); + +var_dump($dll->offsetGet()); +?> +--EXPECTF-- +Warning: SplDoublyLinkedList::offsetGet() expects exactly 1 parameter, 0 given in %s on line %d +NULL diff --git a/ext/spl/tests/SplDoublyLinkedList_offsetGet_param_array.phpt b/ext/spl/tests/SplDoublyLinkedList_offsetGet_param_array.phpt new file mode 100644 index 000000000..6e3a69aaf --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_offsetGet_param_array.phpt @@ -0,0 +1,18 @@ +--TEST--
+SplDoublyLinkedList::offsetGet() with 1st parameter passed as array.
+--CREDITS--
+PHPNW Test Fest 2009 - Jordan Hatch
+--FILE--
+<?php
+
+$array = new SplDoublyLinkedList( );
+
+$get = $array->offsetGet( array( 'fail' ) );
+
+?>
+--EXPECTF--
+Fatal error: Uncaught exception 'OutOfRangeException' with message 'Offset invalid or out of range' in %s
+Stack trace:
+#0 %s
+#1 {main}
+ thrown in %s on line %d
\ No newline at end of file diff --git a/ext/spl/tests/SplDoublyLinkedList_offsetGet_param_string.phpt b/ext/spl/tests/SplDoublyLinkedList_offsetGet_param_string.phpt new file mode 100644 index 000000000..d35aaf16f --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_offsetGet_param_string.phpt @@ -0,0 +1,18 @@ +--TEST--
+SplDoublyLinkedList::offsetGet() with 1st parameter passed as string.
+--CREDITS--
+PHPNW Test Fest 2009 - Jordan Hatch
+--FILE--
+<?php
+
+$array = new SplDoublyLinkedList( );
+
+$get = $array->offsetGet( 'fail' );
+
+?>
+--EXPECTF--
+Fatal error: Uncaught exception 'OutOfRangeException' with message 'Offset invalid or out of range' in %s
+Stack trace:
+#0 %s
+#1 {main}
+ thrown in %s on line %d
\ No newline at end of file diff --git a/ext/spl/tests/SplDoublyLinkedList_offsetSet_invalid_parameter.phpt b/ext/spl/tests/SplDoublyLinkedList_offsetSet_invalid_parameter.phpt new file mode 100644 index 000000000..2447e798a --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_offsetSet_invalid_parameter.phpt @@ -0,0 +1,15 @@ +--TEST-- +SplDoublyLinkedList offsetSet throws error on no parameters +--CREDITS-- +PHPNW TestFest 2009 - Ben Longden +--FILE-- +<?php +$list = new SplDoublyLinkedList(); +$a = $list->offsetSet(); +if(is_null($a)) { + echo 'PASS'; +} +?> +--EXPECTF-- +Warning: SplDoublyLinkedList::offsetSet() expects exactly 2 parameters, 0 given in %s on line %d +PASS diff --git a/ext/spl/tests/SplDoublyLinkedList_offsetSet_one_invalid_parameter.phpt b/ext/spl/tests/SplDoublyLinkedList_offsetSet_one_invalid_parameter.phpt new file mode 100644 index 000000000..244dcd5b0 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_offsetSet_one_invalid_parameter.phpt @@ -0,0 +1,15 @@ +--TEST-- +SplDoublyLinkedList offsetSet throws error only one parameter +--CREDITS-- +PHPNW TestFest 2009 - Ben Longden +--FILE-- +<?php +$list = new SplDoublyLinkedList(); +$a = $list->offsetSet(2); +if(is_null($a)) { + echo 'PASS'; +} +?> +--EXPECTF-- +Warning: SplDoublyLinkedList::offsetSet() expects exactly 2 parameters, 1 given in %s on line %d +PASS diff --git a/ext/spl/tests/SplDoublyLinkedList_offsetUnset_greater_than_elements.phpt b/ext/spl/tests/SplDoublyLinkedList_offsetUnset_greater_than_elements.phpt new file mode 100644 index 000000000..687fcad78 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_offsetUnset_greater_than_elements.phpt @@ -0,0 +1,27 @@ +--TEST-- +Doubly Linked List - offsetUnset > number elements + +--CREDITS-- +PHPNW Test Fest 2009 - Mat Griffin + +--FILE-- +<?php +$ll = new SplDoublyLinkedList(); + +$ll->push('1'); +$ll->push('2'); +$ll->push('3'); + +try { + +$ll->offsetUnset($ll->count() + 1); + +var_dump($ll); + +} catch(Exception $e) { +echo $e->getMessage(); +} + +?> +--EXPECT-- +Offset out of range diff --git a/ext/spl/tests/SplDoublyLinkedList_offsetUnset_negative-parameter.phpt b/ext/spl/tests/SplDoublyLinkedList_offsetUnset_negative-parameter.phpt new file mode 100644 index 000000000..d3d1d7d9a --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_offsetUnset_negative-parameter.phpt @@ -0,0 +1,23 @@ +--TEST-- +Check that SplDoublyLinkedList->offsetUnset() returns an error message when the offset is < 0. +--CREDITS-- +PHPNW Testfest 2009 - Paul Court ( g@rgoyle.com ) +--FILE-- +<?php + // Create a new Doubly Linked List + $dll = new SplDoublyLinkedList(); + + // Add some items to the list + $dll->push(1); + $dll->push(2); + $dll->push(3); + + try { + $dll->offsetUnset(-1); + } + catch (Exception $e) { + echo $e->getMessage() . "\n"; + } +?> +--EXPECT-- +Offset out of range diff --git a/ext/spl/tests/SplDoublyLinkedList_offsetUnset_parameter-larger-num-elements.phpt b/ext/spl/tests/SplDoublyLinkedList_offsetUnset_parameter-larger-num-elements.phpt new file mode 100644 index 000000000..aea73b93b --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_offsetUnset_parameter-larger-num-elements.phpt @@ -0,0 +1,23 @@ +--TEST-- +Check that SplDoublyLinkedList->offsetUnset() returns an error message when the offset is > elements. +--CREDITS-- +PHPNW Testfest 2009 - Paul Court ( g@rgoyle.com ) +--FILE-- +<?php + // Create a new Doubly Linked List + $dll = new SplDoublyLinkedList(); + + // Add some items to the list + $dll->push(1); + $dll->push(2); + $dll->push(3); + + try { + $dll->offsetUnset(3); + } + catch (Exception $e) { + echo $e->getMessage() . "\n"; + } +?> +--EXPECT-- +Offset out of range diff --git a/ext/spl/tests/SplDoublyLinkedList_pop_noParams.phpt b/ext/spl/tests/SplDoublyLinkedList_pop_noParams.phpt new file mode 100644 index 000000000..64f3a4815 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_pop_noParams.phpt @@ -0,0 +1,15 @@ +--TEST-- +Checks that the pop() method of DoublyLinkedList does not accept args. +--CREDITS-- +PHPNW Test Fest 2009 - Rick Ogden +--FILE-- +<?php +$ll = new SplDoublyLinkedList(); +$ll->push(1); +$ll->push(2); + +var_dump($ll->pop(1)); +?> +--EXPECTF-- +Warning: SplDoublyLinkedList::pop() expects exactly 0 parameters, 1 given in %s on line %d +NULL diff --git a/ext/spl/tests/SplDoublyLinkedList_pop_params.phpt b/ext/spl/tests/SplDoublyLinkedList_pop_params.phpt new file mode 100644 index 000000000..0b80babe1 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_pop_params.phpt @@ -0,0 +1,14 @@ +--TEST--
+SplDoublyLinkedList::offsetGet() with no parameter passed.
+--CREDITS--
+PHPNW Test Fest 2009 - Jordan Hatch
+--FILE--
+<?php
+
+$array = new SplDoublyLinkedList( );
+
+$get = $array->pop( 'param' );
+
+?>
+--EXPECTF--
+Warning: SplDoublyLinkedList::pop() expects exactly 0 parameters, 1 given in %s on line %d
\ No newline at end of file diff --git a/ext/spl/tests/SplDoublyLinkedList_push_missing_parameter.phpt b/ext/spl/tests/SplDoublyLinkedList_push_missing_parameter.phpt new file mode 100644 index 000000000..057751c2e --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_push_missing_parameter.phpt @@ -0,0 +1,13 @@ +--TEST-- +Check that SplDoublyLinkedList::push generate a warning and return NULL with missing param +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php +$dll = new SplDoublyLinkedList(); +var_dump($dll->push()); +?> +--EXPECTF-- +Warning: SplDoublyLinkedList::push() expects exactly 1 parameter, 0 given in %s on line %d +NULL + diff --git a/ext/spl/tests/SplDoublyLinkedList_setIteratorMode_param_SplDoublyLinkedList.phpt b/ext/spl/tests/SplDoublyLinkedList_setIteratorMode_param_SplDoublyLinkedList.phpt new file mode 100644 index 000000000..e92121568 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_setIteratorMode_param_SplDoublyLinkedList.phpt @@ -0,0 +1,11 @@ +--TEST--
+Create a SplDoublyLinkedList, call setIteratorMode() and pass a SplDoublyLinkedList object as the parameter.
+--CREDITS--
+Philip Norton philipnorton42@gmail.com
+--FILE--
+<?php
+$dll = new SplDoublyLinkedList(2);
+$dll->setIteratorMode(new SplDoublyLinkedList(2));
+?>
+--EXPECTF--
+Warning: SplDoublyLinkedList::setIteratorMode() expects parameter 1 to be long, object given in %s on line %d
\ No newline at end of file diff --git a/ext/spl/tests/SplDoublyLinkedList_shift_noParams.phpt b/ext/spl/tests/SplDoublyLinkedList_shift_noParams.phpt new file mode 100644 index 000000000..cd4ea5b03 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_shift_noParams.phpt @@ -0,0 +1,15 @@ +--TEST-- +Checks that the shift() method of DoublyLinkedList does not accept args. +--CREDITS-- +PHPNW Test Fest 2009 - Rick Ogden +--FILE-- +<?php +$ll = new SplDoublyLinkedList(); +$ll->push(1); +$ll->push(2); + +var_dump($ll->shift(1)); +?> +--EXPECTF-- +Warning: SplDoublyLinkedList::shift() expects exactly 0 parameters, 1 given in %s on line %d +NULL diff --git a/ext/spl/tests/SplDoublyLinkedList_top_pass_array.phpt b/ext/spl/tests/SplDoublyLinkedList_top_pass_array.phpt new file mode 100644 index 000000000..33d22d755 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_top_pass_array.phpt @@ -0,0 +1,14 @@ +--TEST--
+SplDoublyLinkedList::top() - pass in an unexpected array
+--CREDITS--
+PHPNW Testfest 2009 - Adrian Hardy
+--FILE--
+<?php
+
+$list = new SplDoublyLinkedList();
+$list->push("top");
+$list->top(array());
+
+?>
+--EXPECTF--
+Warning: SplDoublyLinkedList::top() expects exactly 0 parameters, 1 given in %s on line %d
diff --git a/ext/spl/tests/SplDoublyLinkedList_top_pass_float.phpt b/ext/spl/tests/SplDoublyLinkedList_top_pass_float.phpt new file mode 100644 index 000000000..08394f386 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_top_pass_float.phpt @@ -0,0 +1,14 @@ +--TEST--
+SplDoublyLinkedList::top() - pass in an unexpected float parameter
+--CREDITS--
+PHPNW Testfest 2009 - Adrian Hardy
+--FILE--
+<?php
+
+$list = new SplDoublyLinkedList();
+$list->push("top");
+$list->top(3.14159);
+
+?>
+--EXPECTF--
+Warning: SplDoublyLinkedList::top() expects exactly 0 parameters, 1 given in %s on line %d
diff --git a/ext/spl/tests/SplDoublyLinkedList_top_pass_integer.phpt b/ext/spl/tests/SplDoublyLinkedList_top_pass_integer.phpt new file mode 100644 index 000000000..e44097204 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_top_pass_integer.phpt @@ -0,0 +1,14 @@ +--TEST--
+SplDoublyLinkedList::top() - pass in an unexpected integer parameter
+--CREDITS--
+PHPNW Testfest 2009 - Adrian Hardy
+--FILE--
+<?php
+
+$list = new SplDoublyLinkedList();
+$list->push("top");
+$list->top(45);
+
+?>
+--EXPECTF--
+Warning: SplDoublyLinkedList::top() expects exactly 0 parameters, 1 given in %s on line %d
diff --git a/ext/spl/tests/SplDoublyLinkedList_top_pass_null.phpt b/ext/spl/tests/SplDoublyLinkedList_top_pass_null.phpt new file mode 100644 index 000000000..297506e4b --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_top_pass_null.phpt @@ -0,0 +1,14 @@ +--TEST--
+SplDoublyLinkedList::top() - pass in an unexpected null parameter
+--CREDITS--
+PHPNW Testfest 2009 - Adrian Hardy
+--FILE--
+<?php
+
+$list = new SplDoublyLinkedList();
+$list->push("top");
+$list->top(null);
+
+?>
+--EXPECTF--
+Warning: SplDoublyLinkedList::top() expects exactly 0 parameters, 1 given in %s on line %d
diff --git a/ext/spl/tests/SplDoublyLinkedList_unshift_missing_parameter.phpt b/ext/spl/tests/SplDoublyLinkedList_unshift_missing_parameter.phpt new file mode 100644 index 000000000..18afa034b --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_unshift_missing_parameter.phpt @@ -0,0 +1,13 @@ +--TEST-- +Check that SplDoublyLinkedList::unshift generate a warning and return NULL with missing param +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php +$dll = new SplDoublyLinkedList(); +var_dump($dll->unshift()); +?> +--EXPECTF-- +Warning: SplDoublyLinkedList::unshift() expects exactly 1 parameter, 0 given in %s on line %d +NULL + diff --git a/ext/spl/tests/SplDoublylinkedlist_offsetunset_first.phpt b/ext/spl/tests/SplDoublylinkedlist_offsetunset_first.phpt new file mode 100644 index 000000000..4dce4db8d --- /dev/null +++ b/ext/spl/tests/SplDoublylinkedlist_offsetunset_first.phpt @@ -0,0 +1,25 @@ +--TEST-- +SPL: SplDoublyLinkedList : offsetUnset - first element +--CREDITS-- +PHPNW TestFest2009 - Rowan Merewood <rowan@merewood.org> +--FILE-- +<?php +$list = new SplDoublyLinkedList(); +$list->push('oh'); +$list->push('hai'); +$list->push('thar'); +$list->offsetUnset(0); +var_dump($list); +?> +--EXPECTF-- +object(SplDoublyLinkedList)#1 (2) { + [%u|b%"flags":%u|b%"SplDoublyLinkedList":private]=> + int(0) + [%u|b%"dllist":%u|b%"SplDoublyLinkedList":private]=> + array(2) { + [0]=> + %string|unicode%(3) "hai" + [1]=> + %string|unicode%(4) "thar" + } +} diff --git a/ext/spl/tests/SplDoublylinkedlist_offsetunset_first002.phpt b/ext/spl/tests/SplDoublylinkedlist_offsetunset_first002.phpt new file mode 100644 index 000000000..a42e6f904 --- /dev/null +++ b/ext/spl/tests/SplDoublylinkedlist_offsetunset_first002.phpt @@ -0,0 +1,17 @@ +--TEST-- +SPL: SplDoublyLinkedList : offsetUnset - first element +--CREDITS-- +PHPNW TestFest2009 - Rowan Merewood <rowan@merewood.org> +--FILE-- +<?php +$list = new SplDoublyLinkedList(); +$list->push('oh'); +$list->push('hai'); +$list->push('thar'); +echo $list->bottom() . "\n"; +$list->offsetUnset(0); +echo $list->bottom() . "\n"; +?> +--EXPECT-- +oh +hai diff --git a/ext/spl/tests/SplDoublylinkedlist_offsetunset_last.phpt b/ext/spl/tests/SplDoublylinkedlist_offsetunset_last.phpt new file mode 100644 index 000000000..0f5dac19f --- /dev/null +++ b/ext/spl/tests/SplDoublylinkedlist_offsetunset_last.phpt @@ -0,0 +1,25 @@ +--TEST-- +SPL: SplDoublyLinkedList : offsetUnset - last element +--CREDITS-- +PHPNW TestFest2009 - Rowan Merewood <rowan@merewood.org> +--FILE-- +<?php +$list = new SplDoublyLinkedList(); +$list->push('oh'); +$list->push('hai'); +$list->push('thar'); +$list->offsetUnset(2); +var_dump($list); +?> +--EXPECTF-- +object(SplDoublyLinkedList)#1 (2) { + [%u|b%"flags":%u|b%"SplDoublyLinkedList":private]=> + int(0) + [%u|b%"dllist":%u|b%"SplDoublyLinkedList":private]=> + array(2) { + [0]=> + %string|unicode%(2) "oh" + [1]=> + %string|unicode%(3) "hai" + } +} diff --git a/ext/spl/tests/SplFileObject_fflush_basic_001.phpt b/ext/spl/tests/SplFileObject_fflush_basic_001.phpt new file mode 100644 index 000000000..baab156f6 --- /dev/null +++ b/ext/spl/tests/SplFileObject_fflush_basic_001.phpt @@ -0,0 +1,35 @@ +--TEST-- +SplFileObject::fflush function - basic test +--FILE-- +<?php +/* + * test a successful flush +*/ +$obj = New SplFileObject(dirname(__FILE__).'/SplFileObject_testinput.csv'); +var_dump($obj->fflush()); + +/* + * test a unsuccessful flush +*/ +//create a basic stream class +class VariableStream { + var $position; + var $varname; + + function stream_open($path, $mode, $options, &$opened_path) + { + return true; + } +} +stream_wrapper_register("SPLtest", "VariableStream"); +$ftruncate_test = ""; +//end creating stream + +//open an SplFileObject using the above test stream +$obj = New SplFileObject("SPLtest://ftruncate_test"); +var_dump($obj->fflush()); + +?> +--EXPECTF-- +bool(true) +bool(false) diff --git a/ext/spl/tests/SplFileObject_fpassthru_basic.phpt b/ext/spl/tests/SplFileObject_fpassthru_basic.phpt new file mode 100644 index 000000000..55b7481d9 --- /dev/null +++ b/ext/spl/tests/SplFileObject_fpassthru_basic.phpt @@ -0,0 +1,13 @@ +--TEST-- +SplFileObject::fpassthru function - basic functionality test +--FILE-- +<?php +$obj = New SplFileObject(dirname(__FILE__).'/SplFileObject_testinput.csv'); +$obj->fpassthru(); +?> +--EXPECT-- +first,second,third +1,2,3 +4,5,6 +7,8,9 +0,0,0 diff --git a/ext/spl/tests/SplFileObject_fscanf_basic.phpt b/ext/spl/tests/SplFileObject_fscanf_basic.phpt new file mode 100644 index 000000000..5279039f0 --- /dev/null +++ b/ext/spl/tests/SplFileObject_fscanf_basic.phpt @@ -0,0 +1,12 @@ +--TEST-- +SplFileObject::fscanf function - basic functionality test +--FILE-- +<?php +$obj = New SplFileObject(dirname(__FILE__).'/SplFileObject_testinput.csv'); +var_dump($obj->fscanf('%s')); +?> +--EXPECT-- +array(1) { + [0]=> + string(18) "first,second,third" +} diff --git a/ext/spl/tests/SplFileObject_fseek_error_001.phpt b/ext/spl/tests/SplFileObject_fseek_error_001.phpt new file mode 100644 index 000000000..0efeb98cb --- /dev/null +++ b/ext/spl/tests/SplFileObject_fseek_error_001.phpt @@ -0,0 +1,12 @@ +--TEST-- +SplFileObject::fseek function - parameters test +--FILE-- +<?php +$obj = New SplFileObject(__FILE__); +$obj->fseek(1,2,3); +$obj->fseek(); +?> +--EXPECTF-- +Warning: SplFileObject::fseek() expects at most 2 parameters, 3 given %s + +Warning: SplFileObject::fseek() expects at least 1 parameter, 0 given %s diff --git a/ext/spl/tests/SplFileObject_ftruncate_error_001.phpt b/ext/spl/tests/SplFileObject_ftruncate_error_001.phpt new file mode 100644 index 000000000..90b27ec41 --- /dev/null +++ b/ext/spl/tests/SplFileObject_ftruncate_error_001.phpt @@ -0,0 +1,29 @@ +--TEST-- +SplFileObject::ftruncate function - truncating with stream that does not support truncation +--FILE-- +<?php + +//create a basic stream class +class VariableStream { + var $position; + var $varname; + + function stream_open($path, $mode, $options, &$opened_path) + { + return true; + } +} +stream_wrapper_register("SPLtest", "VariableStream"); +$ftruncate_test = ""; +//end creating stream + +//open an SplFileObject using the above test stream +$obj = New SplFileObject("SPLtest://ftruncate_test"); +try { + $obj->ftruncate(1); +} catch (LogicException $e) { + echo($e->getMessage()); +} +?> +--EXPECTF-- +Can't truncate file %s diff --git a/ext/spl/tests/SplFileObject_fwrite_error_001.phpt b/ext/spl/tests/SplFileObject_fwrite_error_001.phpt new file mode 100644 index 000000000..296a1f36c --- /dev/null +++ b/ext/spl/tests/SplFileObject_fwrite_error_001.phpt @@ -0,0 +1,12 @@ +--TEST-- +SplFileObject::fpassthru function - parameters test +--FILE-- +<?php +$obj = New SplFileObject(dirname(__FILE__).'/SplFileObject_testinput.csv'); +$obj->fwrite(); +$obj->fwrite('6,6,6',25,null); +?> +--EXPECTF-- +Warning: SplFileObject::fwrite() expects at least 1 parameter, 0 given in %s + +Warning: SplFileObject::fwrite() expects at most 2 parameters, 3 given in %s diff --git a/ext/spl/tests/SplFileObject_fwrite_variation_001.phpt b/ext/spl/tests/SplFileObject_fwrite_variation_001.phpt new file mode 100644 index 000000000..f8d518f9a --- /dev/null +++ b/ext/spl/tests/SplFileObject_fwrite_variation_001.phpt @@ -0,0 +1,17 @@ +--TEST-- +SplFileObject::fwrite function - writing with two parameters length < input string length +--FILE-- +<?php +$file = dirname(__FILE__).'/SplFileObject_fwrite_variation_001.txt'; +if(file_exists($file)) { + unlink($file); +} +$obj = New SplFileObject($file,'w'); +$obj->fwrite('test_write',4); +var_dump(file_get_contents($file)); +if(file_exists($file)) { + unlink($file); +} +?> +--EXPECT-- +string(4) "test" diff --git a/ext/spl/tests/SplFileObject_fwrite_variation_002.phpt b/ext/spl/tests/SplFileObject_fwrite_variation_002.phpt new file mode 100644 index 000000000..47b1332d2 --- /dev/null +++ b/ext/spl/tests/SplFileObject_fwrite_variation_002.phpt @@ -0,0 +1,17 @@ +--TEST-- +SplFileObject::fwrite function - writing with two parameters, length > input string length +--FILE-- +<?php +$file = dirname(__FILE__).'/SplFileObject_fwrite_variation_002.txt'; +if(file_exists($file)) { + unlink($file); +} +$obj = New SplFileObject($file,'w'); +$obj->fwrite('test_write',12); +var_dump(file_get_contents($file)); +if(file_exists($file)) { + unlink($file); +} +?> +--EXPECT-- +string(10) "test_write" diff --git a/ext/spl/tests/SplFileObject_fwrite_variation_003.phpt b/ext/spl/tests/SplFileObject_fwrite_variation_003.phpt new file mode 100644 index 000000000..8e5c88ebf --- /dev/null +++ b/ext/spl/tests/SplFileObject_fwrite_variation_003.phpt @@ -0,0 +1,18 @@ +--TEST-- +SplFileObject::fwrite function - writing with magic_quotes_runtime ini set +--FILE-- +<?php +ini_set('magic_quotes_runtime',true); +$file = dirname(__FILE__).'/SplFileObject_fwrite_variation_002.txt'; +if(file_exists($file)) { + unlink($file); +} +$obj = New SplFileObject($file,'w'); +$obj->fwrite('"test" \'write\''); +var_dump(file_get_contents($file)); +if(file_exists($file)) { + unlink($file); +} +?> +--EXPECT-- +string(18) "\"test\" \'write\'" diff --git a/ext/spl/tests/SplFileObject_getCsvControl_basic_001.phpt b/ext/spl/tests/SplFileObject_getCsvControl_basic_001.phpt new file mode 100644 index 000000000..e21f08fa2 --- /dev/null +++ b/ext/spl/tests/SplFileObject_getCsvControl_basic_001.phpt @@ -0,0 +1,15 @@ +--TEST-- +SplFileObject::getCsvControl function - basic test +--FILE-- +<?php +$obj = New SplFileObject(dirname(__FILE__).'/SplFileObject_testinput.csv'); +var_dump($obj->getCsvControl()); + +?> +--EXPECTF-- +array(2) { + [0]=> + %unicode|string%(1) "," + [1]=> + %unicode|string%(1) """ +} diff --git a/ext/spl/tests/SplFileObject_seek_error_001.phpt b/ext/spl/tests/SplFileObject_seek_error_001.phpt new file mode 100644 index 000000000..bcf44b098 --- /dev/null +++ b/ext/spl/tests/SplFileObject_seek_error_001.phpt @@ -0,0 +1,19 @@ +--TEST-- +SplFileObject::seek function - test parameters +--FILE-- +<?php +$obj = New SplFileObject(__FILE__); +$obj->seek(1,2); +$obj->seek(); +try { + $obj->seek(-1); +} catch (LogicException $e) { + echo($e->getMessage()); +} +?> +--EXPECTF-- + +Warning: SplFileObject::seek() expects exactly 1 parameter, 2 given in %s + +Warning: SplFileObject::seek() expects exactly 1 parameter, 0 given in %s +Can't seek file %s to negative line %s diff --git a/ext/spl/tests/SplFileObject_testinput.csv b/ext/spl/tests/SplFileObject_testinput.csv new file mode 100644 index 000000000..41a9e31c8 --- /dev/null +++ b/ext/spl/tests/SplFileObject_testinput.csv @@ -0,0 +1,5 @@ +first,second,third +1,2,3 +4,5,6 +7,8,9 +0,0,0 diff --git a/ext/spl/tests/SplFixedArray__construct_param_array.phpt b/ext/spl/tests/SplFixedArray__construct_param_array.phpt new file mode 100644 index 000000000..ca0cc197d --- /dev/null +++ b/ext/spl/tests/SplFixedArray__construct_param_array.phpt @@ -0,0 +1,12 @@ +--TEST--
+SplFixedArray::__construct() with array passed as integer.
+--CREDITS--
+PHPNW Test Fest 2009 - Jordan Hatch
+--FILE--
+<?php
+
+$array = new SplFixedArray( array("string", 1) );
+
+?>
+--EXPECTF--
+Warning: SplFixedArray::__construct() expects parameter 1 to be long, array given in %s on line %d
\ No newline at end of file diff --git a/ext/spl/tests/SplFixedArray__construct_param_float.phpt b/ext/spl/tests/SplFixedArray__construct_param_float.phpt new file mode 100644 index 000000000..833738699 --- /dev/null +++ b/ext/spl/tests/SplFixedArray__construct_param_float.phpt @@ -0,0 +1,14 @@ +--TEST--
+SplFixedArray::__construct() with float passed as parameter.
+--CREDITS--
+PHPNW Test Fest 2009 - Jordan Hatch
+--FILE--
+<?php
+
+$array = new SplFixedArray( 3.141 );
+
+echo $array->getSize();
+
+?>
+--EXPECT--
+3
\ No newline at end of file diff --git a/ext/spl/tests/SplFixedArray__construct_param_null.phpt b/ext/spl/tests/SplFixedArray__construct_param_null.phpt new file mode 100644 index 000000000..2b631c537 --- /dev/null +++ b/ext/spl/tests/SplFixedArray__construct_param_null.phpt @@ -0,0 +1,16 @@ +--TEST--
+SplFixedArray::__construct() with null passed as parameter.
+--CREDITS--
+PHPNW Test Fest 2009 - Jordan Hatch
+--FILE--
+<?php
+
+$array = new SplFixedArray( NULL );
+
+print_r( $array );
+
+?>
+--EXPECTF--
+SplFixedArray Object
+(
+)
\ No newline at end of file diff --git a/ext/spl/tests/SplFixedArray__construct_param_string.phpt b/ext/spl/tests/SplFixedArray__construct_param_string.phpt new file mode 100644 index 000000000..56a2dd809 --- /dev/null +++ b/ext/spl/tests/SplFixedArray__construct_param_string.phpt @@ -0,0 +1,12 @@ +--TEST--
+SplFixedArray::__construct() with string passed as parameter.
+--CREDITS--
+PHPNW Test Fest 2009 - Jordan Hatch
+--FILE--
+<?php
+
+$array = new SplFixedArray( "string" );
+
+?>
+--EXPECTF--
+Warning: SplFixedArray::__construct() expects parameter 1 to be long, %unicode_string_optional% given in %s on line %d
diff --git a/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt b/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt new file mode 100644 index 000000000..ae0f9e998 --- /dev/null +++ b/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt @@ -0,0 +1,13 @@ +--TEST--
+Create an SplFixedArray using an SplFixedArray object.
+--CREDITS--
+Philip Norton philipnorton42@gmail.com
+--FILE--
+<?php
+$array = new SplFixedArray(new SplFixedArray(3));
+var_dump($array);
+?>
+--EXPECTF--
+Warning: SplFixedArray::__construct() expects parameter 1 to be long, object given in %s on line %d
+object(SplFixedArray)#1 (0) {
+}
\ No newline at end of file diff --git a/ext/spl/tests/SplFixedArray_count_checkParams.phpt b/ext/spl/tests/SplFixedArray_count_checkParams.phpt new file mode 100644 index 000000000..5cbe2e80c --- /dev/null +++ b/ext/spl/tests/SplFixedArray_count_checkParams.phpt @@ -0,0 +1,16 @@ +--TEST-- +Makes sure that an integer cannot be passed into the count() method of the splFixedArray. +--CREDITS-- +PHPNW Test Fest 2009 - Rick Ogden +--FILE-- +<?php +$ar = new SplFixedArray(3); +$ar[0] = 1; +$ar[1] = 2; +$ar[2] = 3; + +echo $ar->count(3); +?> +--EXPECTF-- +Warning: SplFixedArray::count() expects exactly 0 parameters, 1 given in %s on line %d + diff --git a/ext/spl/tests/SplFixedArray_count_param_int.phpt b/ext/spl/tests/SplFixedArray_count_param_int.phpt new file mode 100644 index 000000000..db379906a --- /dev/null +++ b/ext/spl/tests/SplFixedArray_count_param_int.phpt @@ -0,0 +1,11 @@ +--TEST--
+Creates array, uses the count function to get the size of the array, but passes a parameter.
+--CREDITS--
+Philip Norton philipnorton42@gmail.com
+--FILE--
+<?php
+$array = new SplFixedArray(5);
+echo $array->count(3);
+?>
+--EXPECTF--
+Warning: SplFixedArray::count() expects exactly 0 parameters, 1 given in %s on line %d
\ No newline at end of file diff --git a/ext/spl/tests/SplFixedArray_current_param.phpt b/ext/spl/tests/SplFixedArray_current_param.phpt new file mode 100644 index 000000000..46df10d73 --- /dev/null +++ b/ext/spl/tests/SplFixedArray_current_param.phpt @@ -0,0 +1,24 @@ +--TEST--
+SplFixedArray::current() with a parameter. *BUG*
+--CREDITS--
+PHPNW Test Fest 2009 - Jordan Hatch
+--FILE--
+<?php
+
+$array = new SplFixedArray( 3 );
+
+$array[0] = "Hello";
+$array[1] = "world";
+$array[2] = "elePHPant";
+
+foreach ( $array as $value ) {
+ echo $array->current( array("this","should","not","execute") );
+}
+
+?>
+--EXPECTF--
+Warning: SplFixedArray::current() expects exactly 0 parameters, 1 given in %s on line %d
+
+Warning: SplFixedArray::current() expects exactly 0 parameters, 1 given in %s on line %d
+
+Warning: SplFixedArray::current() expects exactly 0 parameters, 1 given in %s on line %d
diff --git a/ext/spl/tests/SplFixedArray_fromArray_invalid_parameter_001.phpt b/ext/spl/tests/SplFixedArray_fromArray_invalid_parameter_001.phpt new file mode 100644 index 000000000..36ecf4645 --- /dev/null +++ b/ext/spl/tests/SplFixedArray_fromArray_invalid_parameter_001.phpt @@ -0,0 +1,10 @@ +--TEST-- +pass an integer into fromArray() +--CREDITS-- +PHPNW Testfest 2009 - Lorna Mitchell +--FILE-- +<?php +echo SplFixedArray::fromArray(17954); +?> +--EXPECTF-- +Warning: SplFixedArray::fromArray() expects parameter 1 to be array, integer given in %s on line %d diff --git a/ext/spl/tests/SplFixedArray_fromArray_invalid_parameter_002.phpt b/ext/spl/tests/SplFixedArray_fromArray_invalid_parameter_002.phpt new file mode 100644 index 000000000..ba81428af --- /dev/null +++ b/ext/spl/tests/SplFixedArray_fromArray_invalid_parameter_002.phpt @@ -0,0 +1,10 @@ +--TEST-- +pass a string into fromArray() +--CREDITS-- +PHPNW Testfest 2009 - Lorna Mitchell +--FILE-- +<?php +echo SplFixedArray::fromArray('hello'); +?> +--EXPECTF-- +Warning: SplFixedArray::fromArray() expects parameter 1 to be array, %unicode_string_optional% given in %s on line %d diff --git a/ext/spl/tests/SplFixedArray_fromarray_indexes.phpt b/ext/spl/tests/SplFixedArray_fromarray_indexes.phpt new file mode 100644 index 000000000..faac20f03 --- /dev/null +++ b/ext/spl/tests/SplFixedArray_fromarray_indexes.phpt @@ -0,0 +1,22 @@ +--TEST--
+Create a SplFixedArray from an array using the fromArray() function use the default behaviour of preserve the indexes.
+--CREDITS--
+Philip Norton philipnorton42@gmail.com
+--FILE--
+<?php
+$array = SplFixedArray::fromArray(array(1 => 1,
+ 2 => '2',
+ 3 => false));
+var_dump($array);
+?>
+--EXPECTF--
+object(SplFixedArray)#1 (4) {
+ [0]=>
+ NULL
+ [1]=>
+ int(1)
+ [2]=>
+ %string|unicode%(1) "2"
+ [3]=>
+ bool(false)
+}
diff --git a/ext/spl/tests/SplFixedArray_fromarray_non_indexes.phpt b/ext/spl/tests/SplFixedArray_fromarray_non_indexes.phpt new file mode 100644 index 000000000..a78293bc5 --- /dev/null +++ b/ext/spl/tests/SplFixedArray_fromarray_non_indexes.phpt @@ -0,0 +1,21 @@ +--TEST--
+Create a SplFixedArray from an array using the fromArray() function don't try to preserve the indexes.
+--CREDITS--
+Philip Norton philipnorton42@gmail.com
+--FILE--
+<?php
+$array = SplFixedArray::fromArray(array(1 => 1,
+ 2 => '2',
+ 3 => false),
+ false);
+var_dump($array);
+?>
+--EXPECTF--
+object(SplFixedArray)#1 (3) {
+ [0]=>
+ int(1)
+ [1]=>
+ %string|unicode%(1) "2"
+ [2]=>
+ bool(false)
+}
diff --git a/ext/spl/tests/SplFixedArray_fromarray_param_boolean.phpt b/ext/spl/tests/SplFixedArray_fromarray_param_boolean.phpt new file mode 100644 index 000000000..36a4ab1eb --- /dev/null +++ b/ext/spl/tests/SplFixedArray_fromarray_param_boolean.phpt @@ -0,0 +1,10 @@ +--TEST--
+Tries to create a SplFixedArray using a boolean value.
+--CREDITS--
+Philip Norton philipnorton42@gmail.com
+--FILE--
+<?php
+$array = SplFixedArray::fromArray(true);
+?>
+--EXPECTF--
+Warning: SplFixedArray::fromArray() expects parameter 1 to be array, boolean given in %s on line %d
\ No newline at end of file diff --git a/ext/spl/tests/SplFixedArray_fromarray_param_multiarray.phpt b/ext/spl/tests/SplFixedArray_fromarray_param_multiarray.phpt new file mode 100644 index 000000000..226b38bda --- /dev/null +++ b/ext/spl/tests/SplFixedArray_fromarray_param_multiarray.phpt @@ -0,0 +1,17 @@ +--TEST--
+Tries to create a SplFixedArray using the fromArray() function and a multi dimentional array.
+--CREDITS--
+Philip Norton philipnorton42@gmail.com
+--FILE--
+<?php
+$array = SplFixedArray::fromArray(array(array('1')));
+var_dump($array);
+?>
+--EXPECTF--
+object(SplFixedArray)#1 (1) {
+ [0]=>
+ array(1) {
+ [0]=>
+ %string|unicode%(1) "1"
+ }
+}
diff --git a/ext/spl/tests/SplFixedArray_getSize_pass_param.phpt b/ext/spl/tests/SplFixedArray_getSize_pass_param.phpt new file mode 100644 index 000000000..d60c4bd8f --- /dev/null +++ b/ext/spl/tests/SplFixedArray_getSize_pass_param.phpt @@ -0,0 +1,12 @@ +--TEST--
+SplFixedArray::getSize() pass a parameter when none are expected
+--CREDITS--
+PHPNW Testfest 2009 - Adrian Hardy
+--FILE--
+<?php
+$fixed_array = new SplFixedArray(2);
+echo "*test* ".$fixed_array->getSize(3);
+?>
+--EXPECTF--
+Warning: SplFixedArray::getSize() expects exactly 0 parameters, 1 given in %s on line %d
+*test*
diff --git a/ext/spl/tests/SplFixedArray_key_param.phpt b/ext/spl/tests/SplFixedArray_key_param.phpt new file mode 100644 index 000000000..a0b24058f --- /dev/null +++ b/ext/spl/tests/SplFixedArray_key_param.phpt @@ -0,0 +1,24 @@ +--TEST--
+SplFixedArray::key() with a parameter passed. This is a bug and an error should be called.
+--CREDITS--
+PHPNW Test Fest 2009 - Jordan Hatch
+--FILE--
+<?php
+
+$array = new SplFixedArray( 3 );
+
+$array[0] = "Hello";
+$array[1] = "world";
+$array[2] = "elePHPant";
+
+foreach ( $array as $value ) {
+ echo $array->key( array("this","should","not","execute") );
+}
+
+?>
+--EXPECTF--
+Warning: SplFixedArray::key() expects exactly 0 parameters, 1 given in %s on line %d
+
+Warning: SplFixedArray::key() expects exactly 0 parameters, 1 given in %s on line %d
+
+Warning: SplFixedArray::key() expects exactly 0 parameters, 1 given in %s on line %d
diff --git a/ext/spl/tests/SplFixedArray_key_setsize.phpt b/ext/spl/tests/SplFixedArray_key_setsize.phpt new file mode 100644 index 000000000..9562a6025 --- /dev/null +++ b/ext/spl/tests/SplFixedArray_key_setsize.phpt @@ -0,0 +1,20 @@ +--TEST--
+SplFixedArray::key() when the array has a size higher than the amount of values specified.
+--CREDITS--
+PHPNW Test Fest 2009 - Jordan Hatch
+--FILE--
+<?php
+
+$array = new SplFixedArray( 4 );
+
+$array[0] = "Hello";
+$array[1] = "world";
+$array[2] = "elePHPant";
+
+foreach ( $array as $value ) {
+ echo $array->key( );
+}
+
+?>
+--EXPECT--
+0123
\ No newline at end of file diff --git a/ext/spl/tests/SplFixedArray_next_param.phpt b/ext/spl/tests/SplFixedArray_next_param.phpt new file mode 100644 index 000000000..f7a40c107 --- /dev/null +++ b/ext/spl/tests/SplFixedArray_next_param.phpt @@ -0,0 +1,18 @@ +--TEST--
+SplFixedArray::next() with a parameter. *BUG*
+--CREDITS--
+PHPNW Test Fest 2009 - Jordan Hatch
+--FILE--
+<?php
+
+$array = new SplFixedArray( 4 );
+
+$array[0] = "Hello";
+$array[1] = "world";
+$array[2] = "elePHPant";
+
+$array->next( "invalid" );
+
+?>
+--EXPECTF--
+Warning: SplFixedArray::next() expects exactly 0 parameters, 1 given in %s on line %d
diff --git a/ext/spl/tests/SplFixedArray_offsetExists_invalid_parameter.phpt b/ext/spl/tests/SplFixedArray_offsetExists_invalid_parameter.phpt new file mode 100644 index 000000000..76ee2f58a --- /dev/null +++ b/ext/spl/tests/SplFixedArray_offsetExists_invalid_parameter.phpt @@ -0,0 +1,15 @@ +--TEST-- +SPL FixedArray offsetExists throws error only one parameter +--CREDITS-- +PHPNW TestFest 2009 - Ben Longden +--FILE-- +<?php +$array = new SplFixedArray(5); +$a = $array->offsetExists(); +if(is_null($a)) { + echo 'PASS'; +} +?> +--EXPECTF-- +Warning: SplFixedArray::offsetExists() expects exactly 1 parameter, 0 given in %s on line %d +PASS diff --git a/ext/spl/tests/SplFixedArray_offsetExists_less_than_zero.phpt b/ext/spl/tests/SplFixedArray_offsetExists_less_than_zero.phpt new file mode 100644 index 000000000..9bfda3407 --- /dev/null +++ b/ext/spl/tests/SplFixedArray_offsetExists_less_than_zero.phpt @@ -0,0 +1,13 @@ +--TEST-- +SPL FixedArray offsetExists behaviour on a negative index +--CREDITS-- +PHPNW TestFest 2009 - Ben Longden +--FILE-- +<?php +$array = new SplFixedArray(5); +if($array->offsetExists(-10) === false) { + echo 'PASS'; +} +?> +--EXPECT-- +PASS diff --git a/ext/spl/tests/SplFixedArray_offsetGet_invalid_parameter.phpt b/ext/spl/tests/SplFixedArray_offsetGet_invalid_parameter.phpt new file mode 100644 index 000000000..71a1bf80f --- /dev/null +++ b/ext/spl/tests/SplFixedArray_offsetGet_invalid_parameter.phpt @@ -0,0 +1,16 @@ +--TEST-- +SPL FixedArray offsetGet throws error on no parameter +--CREDITS-- +PHPNW TestFest 2009 - Ben Longden +--FILE-- +<?php +$array = new SplFixedArray(5); +$array[0] = 'a'; +$a = $array->offsetGet(); +if(is_null($a)) { + echo 'PASS'; +} +?> +--EXPECTF-- +Warning: SplFixedArray::offsetGet() expects exactly 1 parameter, 0 given in %s on line %d +PASS diff --git a/ext/spl/tests/SplFixedArray_offsetSet_invalid_parameter.phpt b/ext/spl/tests/SplFixedArray_offsetSet_invalid_parameter.phpt new file mode 100644 index 000000000..4e43a525f --- /dev/null +++ b/ext/spl/tests/SplFixedArray_offsetSet_invalid_parameter.phpt @@ -0,0 +1,15 @@ +--TEST-- +SPL FixedArray offsetSet throws error on no parameters +--CREDITS-- +PHPNW TestFest 2009 - Ben Longden +--FILE-- +<?php +$array = new SplFixedArray(5); +$a = $array->offsetSet(); +if(is_null($a)) { + echo 'PASS'; +} +?> +--EXPECTF-- +Warning: SplFixedArray::offsetSet() expects exactly 2 parameters, 0 given in %s on line %d +PASS diff --git a/ext/spl/tests/SplFixedArray_offsetSet_one_invalid_parameter.phpt b/ext/spl/tests/SplFixedArray_offsetSet_one_invalid_parameter.phpt new file mode 100644 index 000000000..c19cd0176 --- /dev/null +++ b/ext/spl/tests/SplFixedArray_offsetSet_one_invalid_parameter.phpt @@ -0,0 +1,15 @@ +--TEST-- +SPL FixedArray offsetSet throws error only one parameter +--CREDITS-- +PHPNW TestFest 2009 - Ben Longden +--FILE-- +<?php +$array = new SplFixedArray(5); +$a = $array->offsetSet(2); +if(is_null($a)) { + echo 'PASS'; +} +?> +--EXPECTF-- +Warning: SplFixedArray::offsetSet() expects exactly 2 parameters, 1 given in %s on line %d +PASS diff --git a/ext/spl/tests/SplFixedArray_offsetUnset_invalid_parameter.phpt b/ext/spl/tests/SplFixedArray_offsetUnset_invalid_parameter.phpt new file mode 100644 index 000000000..40a372bd9 --- /dev/null +++ b/ext/spl/tests/SplFixedArray_offsetUnset_invalid_parameter.phpt @@ -0,0 +1,15 @@ +--TEST-- +SPL FixedArray offsetUnset throws error on no parameter +--CREDITS-- +PHPNW TestFest 2009 - Ben Longden +--FILE-- +<?php +$array = new SplFixedArray(5); +$a = $array->offsetUnset(); +if(is_null($a)) { + echo 'PASS'; +} +?> +--EXPECTF-- +Warning: SplFixedArray::offsetUnset() expects exactly 1 parameter, 0 given in %s on line %d +PASS diff --git a/ext/spl/tests/SplFixedArray_offsetUnset_string.phpt b/ext/spl/tests/SplFixedArray_offsetUnset_string.phpt new file mode 100644 index 000000000..21976b552 --- /dev/null +++ b/ext/spl/tests/SplFixedArray_offsetUnset_string.phpt @@ -0,0 +1,33 @@ +--TEST-- +Check removing an item from an array when the offset is not an integer. +--CREDITS-- +PHPNW Testfest 2009 - Paul Court ( g@rgoyle.com ) +--FILE-- +<?php + // Create a fixed array + $fixedArray = new SplFixedArray(5); + + // Fill it up + for ($i=0; $i < 5; $i++) { + $fixedArray[$i] = "PHPNW Testfest"; + } + + // remove an item + $fixedArray->offsetUnset("4"); + + var_dump($fixedArray); + +?> +--EXPECTF-- +object(SplFixedArray)#1 (5) { + [0]=> + %string|unicode%(14) "PHPNW Testfest" + [1]=> + %string|unicode%(14) "PHPNW Testfest" + [2]=> + %string|unicode%(14) "PHPNW Testfest" + [3]=> + %string|unicode%(14) "PHPNW Testfest" + [4]=> + NULL +} diff --git a/ext/spl/tests/SplFixedArray_rewind_param.phpt b/ext/spl/tests/SplFixedArray_rewind_param.phpt new file mode 100644 index 000000000..5d1721946 --- /dev/null +++ b/ext/spl/tests/SplFixedArray_rewind_param.phpt @@ -0,0 +1,18 @@ +--TEST--
+SplFixedArray::rewind() with a parameter. *BUG*
+--CREDITS--
+PHPNW Test Fest 2009 - Jordan Hatch
+--FILE--
+<?php
+
+$array = new SplFixedArray( 4 );
+
+$array[0] = "Hello";
+$array[1] = "world";
+$array[2] = "elePHPant";
+
+$array->rewind( "invalid" );
+
+?>
+--EXPECTF--
+Warning: SplFixedArray::rewind() expects exactly 0 parameters, 1 given in %s on line %d
diff --git a/ext/spl/tests/SplFixedArray_setSize_filled_to_smaller.phpt b/ext/spl/tests/SplFixedArray_setSize_filled_to_smaller.phpt new file mode 100644 index 000000000..46922b838 --- /dev/null +++ b/ext/spl/tests/SplFixedArray_setSize_filled_to_smaller.phpt @@ -0,0 +1,22 @@ +--TEST--
+Create array, fills it with and resizes it to lower value.
+--CREDITS--
+Philip Norton philipnorton42@gmail.com
+--FILE--
+<?php
+$array = new SplFixedArray(5);
+$array[0] = 1;
+$array[1] = 1;
+$array[2] = 1;
+$array[3] = 1;
+$array[4] = 1;
+$array->setSize(2);
+var_dump($array);
+?>
+--EXPECT--
+object(SplFixedArray)#1 (2) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(1)
+}
\ No newline at end of file diff --git a/ext/spl/tests/SplFixedArray_setSize_param_array.phpt b/ext/spl/tests/SplFixedArray_setSize_param_array.phpt new file mode 100644 index 000000000..6967e47bd --- /dev/null +++ b/ext/spl/tests/SplFixedArray_setSize_param_array.phpt @@ -0,0 +1,18 @@ +--TEST--
+SplFixedArray::setSize() with an array parameter
+--CREDITS--
+PHPNW Testfest 2009 - Adrian Hardy
+--FILE--
+<?php
+$fixed_array = new SplFixedArray(2);
+$fixed_array->setSize(array());
+var_dump($fixed_array);
+?>
+--EXPECTF--
+Warning: SplFixedArray::setSize() expects parameter 1 to be long, array given in %s on line %d
+object(SplFixedArray)#1 (2) {
+ [0]=>
+ NULL
+ [1]=>
+ NULL
+}
diff --git a/ext/spl/tests/SplFixedArray_setSize_param_float.phpt b/ext/spl/tests/SplFixedArray_setSize_param_float.phpt new file mode 100644 index 000000000..2cafa8467 --- /dev/null +++ b/ext/spl/tests/SplFixedArray_setSize_param_float.phpt @@ -0,0 +1,19 @@ +--TEST--
+SplFixedArray::setSize() with a float param
+--CREDITS--
+PHPNW Testfest 2009 - Adrian Hardy
+--FILE--
+<?php
+$fixed_array = new SplFixedArray(2);
+$fixed_array->setSize(3.14159);
+var_dump($fixed_array);
+?>
+--EXPECTF--
+object(SplFixedArray)#1 (3) {
+ [0]=>
+ NULL
+ [1]=>
+ NULL
+ [2]=>
+ NULL
+}
diff --git a/ext/spl/tests/SplFixedArray_setSize_param_null.phpt b/ext/spl/tests/SplFixedArray_setSize_param_null.phpt new file mode 100644 index 000000000..d2dec401d --- /dev/null +++ b/ext/spl/tests/SplFixedArray_setSize_param_null.phpt @@ -0,0 +1,13 @@ +--TEST--
+SplFixedArray::setSize() with a null parameter
+--CREDITS--
+PHPNW Testfest 2009 - Adrian Hardy
+--FILE--
+<?php
+$fixed_array = new SplFixedArray(2);
+$fixed_array->setSize(null);
+var_dump($fixed_array);
+?>
+--EXPECT--
+object(SplFixedArray)#1 (0) {
+}
diff --git a/ext/spl/tests/SplFixedArray_setSize_reduce.phpt b/ext/spl/tests/SplFixedArray_setSize_reduce.phpt new file mode 100644 index 000000000..eb8e1d9dc --- /dev/null +++ b/ext/spl/tests/SplFixedArray_setSize_reduce.phpt @@ -0,0 +1,22 @@ +--TEST-- +SPL FixedArray can reduce size of array +--CREDITS-- +PHPNW TestFest 2009 - Ben Longden +--FILE-- +<?php +$array = new SplFixedArray(5); +$array[0] = 'a'; +$array[1] = 'b'; +$array[2] = 'c'; +$array[3] = 'd'; +$array[4] = 'e'; +$array->setSize(3); +print_r($array); +?> +--EXPECT-- +SplFixedArray Object +( + [0] => a + [1] => b + [2] => c +) diff --git a/ext/spl/tests/SplFixedArray_setsize_001.phpt b/ext/spl/tests/SplFixedArray_setsize_001.phpt new file mode 100644 index 000000000..925912ceb --- /dev/null +++ b/ext/spl/tests/SplFixedArray_setsize_001.phpt @@ -0,0 +1,22 @@ +--TEST-- +SPL: FixedArray: setsize - populate array, then shrink +--CREDITS-- +PHPNW TestFest2009 - Rowan Merewood <rowan@merewood.org> +--FILE-- +<?php +$array = new SplFixedArray(5); +$array[0] = 'one'; +$array[1] = 'two'; +$array[2] = 'three'; +$array[3] = 'four'; +$array[4] = 'five'; +$array->setSize(2); +var_dump($array); +?> +--EXPECTF-- +object(SplFixedArray)#1 (2) { + [0]=> + %string|unicode%(3) "one" + [1]=> + %string|unicode%(3) "two" +} diff --git a/ext/spl/tests/SplFixedArray_setsize_grow.phpt b/ext/spl/tests/SplFixedArray_setsize_grow.phpt new file mode 100644 index 000000000..0c9f6d83e --- /dev/null +++ b/ext/spl/tests/SplFixedArray_setsize_grow.phpt @@ -0,0 +1,30 @@ +--TEST--
+SplFixedArray::setSize() grow
+--CREDITS--
+PHPNW Test Fest 2009 - Jordan Hatch
+--FILE--
+<?php
+
+echo "\n";
+
+$array = new SplFixedArray(2);
+
+$array[0] = "Value 1";
+$array[1] = "Value 2";
+
+$array->setSize(4);
+
+$array[2] = "Value 3";
+$array[3] = "Value 4";
+
+print_r($array);
+
+?>
+--EXPECT--
+SplFixedArray Object
+(
+ [0] => Value 1
+ [1] => Value 2
+ [2] => Value 3
+ [3] => Value 4
+)
\ No newline at end of file diff --git a/ext/spl/tests/SplFixedArray_setsize_shrink.phpt b/ext/spl/tests/SplFixedArray_setsize_shrink.phpt new file mode 100644 index 000000000..2130cf868 --- /dev/null +++ b/ext/spl/tests/SplFixedArray_setsize_shrink.phpt @@ -0,0 +1,28 @@ +--TEST-- +shrink a full array of integers +--CREDITS-- +PHPNW Testfest 2009 - Lorna Mitchell +--FILE-- +<?php +$array = new SplFixedArray(5); +$array[0] = 1; +$array[1] = 1; +$array[2] = 1; +$array[3] = 1; +$array[4] = 1; + +$array->setSize(4); +var_dump($array); + +?> +--EXPECT-- +object(SplFixedArray)#1 (4) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) + [3]=> + int(1) +} diff --git a/ext/spl/tests/SplFixedArray_toArray_with-params.phpt b/ext/spl/tests/SplFixedArray_toArray_with-params.phpt new file mode 100644 index 000000000..8864362c6 --- /dev/null +++ b/ext/spl/tests/SplFixedArray_toArray_with-params.phpt @@ -0,0 +1,19 @@ +--TEST-- +Check that passing a parameter to toArray() produces a correct error +--CREDITS-- +PHPNW Testfest 2009 - Paul Court ( g@rgoyle.com ) +--FILE-- +<?php + // Create a fixed array + $fixedArray = new SplFixedArray(5); + + // Fill it up + for ($i=0; $i < 5; $i++) { + $fixedArray[$i] = "PHPNW Testfest"; + } + + // Test count() returns correct error when parameters are passed. + $fixedArray->count(1); +?> +--EXPECTF-- +Warning: SplFixedArray::count() expects exactly 0 parameters, %d given in %s on line %d diff --git a/ext/spl/tests/SplFixedarray_offsetExists_larger.phpt b/ext/spl/tests/SplFixedarray_offsetExists_larger.phpt new file mode 100644 index 000000000..9449d64d8 --- /dev/null +++ b/ext/spl/tests/SplFixedarray_offsetExists_larger.phpt @@ -0,0 +1,15 @@ +--TEST-- +Checks that offsetExists() does not accept a value larger than the array. +--CREDITS-- + PHPNW Test Fest 2009 - Rick Ogden +--FILE-- +<?php +$ar = new SplFixedArray(3); +$ar[0] = 1; +$ar[1] = 2; +$ar[2] = 3; + +var_dump($ar->offsetExists(4)); +?> +--EXPECT-- +bool(false) diff --git a/ext/spl/tests/SplHeap_count_invalid_parameter.phpt b/ext/spl/tests/SplHeap_count_invalid_parameter.phpt new file mode 100644 index 000000000..727790eab --- /dev/null +++ b/ext/spl/tests/SplHeap_count_invalid_parameter.phpt @@ -0,0 +1,47 @@ +--TEST-- +Check that SplHeap::count generate a warning and returns NULL when param passed +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$data_provider = array( + new stdClass, + array(), + true, + "string", + 12345, + 1.2345, + NULL +); + +foreach($data_provider as $input) { + + $h = new SplMaxHeap(); + + var_dump($h->count($input)); +} + +?> +--EXPECTF-- +Warning: SplHeap::count() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplHeap::count() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplHeap::count() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplHeap::count() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplHeap::count() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplHeap::count() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplHeap::count() expects exactly 0 parameters, 1 given in %s on line %d +NULL + diff --git a/ext/spl/tests/SplHeap_extract_invalid_parameter.phpt b/ext/spl/tests/SplHeap_extract_invalid_parameter.phpt new file mode 100644 index 000000000..ba0397639 --- /dev/null +++ b/ext/spl/tests/SplHeap_extract_invalid_parameter.phpt @@ -0,0 +1,47 @@ +--TEST-- +Check that SplHeap::extract generate a warning and returns NULL when param passed +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$data_provider = array( + new stdClass, + array(), + true, + "string", + 12345, + 1.2345, + NULL +); + +foreach($data_provider as $input) { + + $h = new SplMaxHeap(); + + var_dump($h->extract($input)); +} + +?> +--EXPECTF-- +Warning: SplHeap::extract() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplHeap::extract() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplHeap::extract() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplHeap::extract() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplHeap::extract() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplHeap::extract() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplHeap::extract() expects exactly 0 parameters, 1 given in %s on line %d +NULL + diff --git a/ext/spl/tests/SplHeap_insert_invalid_parameter.phpt b/ext/spl/tests/SplHeap_insert_invalid_parameter.phpt new file mode 100644 index 000000000..86c6b6370 --- /dev/null +++ b/ext/spl/tests/SplHeap_insert_invalid_parameter.phpt @@ -0,0 +1,16 @@ +--TEST-- +Check that SplHeap::insert generate a warning and returns NULL when $value is missing +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$h = new SplMaxHeap(); + +var_dump($h->insert()); + +?> +--EXPECTF-- +Warning: SplHeap::insert() expects exactly 1 parameter, 0 given in %s on line %d +NULL + diff --git a/ext/spl/tests/SplHeap_isEmpty.phpt b/ext/spl/tests/SplHeap_isEmpty.phpt new file mode 100644 index 000000000..e179dbc8e --- /dev/null +++ b/ext/spl/tests/SplHeap_isEmpty.phpt @@ -0,0 +1,15 @@ +--TEST-- +Check that SplHeap::isEmpty standard success test +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$h = new SplMaxHeap(); + +var_dump($h->isEmpty()); + +?> +--EXPECTF-- +bool(true) + diff --git a/ext/spl/tests/SplHeap_isEmpty_invalid_parameter.phpt b/ext/spl/tests/SplHeap_isEmpty_invalid_parameter.phpt new file mode 100644 index 000000000..021aff423 --- /dev/null +++ b/ext/spl/tests/SplHeap_isEmpty_invalid_parameter.phpt @@ -0,0 +1,47 @@ +--TEST-- +Check that SplHeap::isEmpty generate a warning and returns NULL when param passed +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$data_provider = array( + new stdClass, + array(), + true, + "string", + 12345, + 1.2345, + NULL +); + +foreach($data_provider as $input) { + + $h = new SplMaxHeap(); + + var_dump($h->isEmpty($input)); +} + +?> +--EXPECTF-- +Warning: SplHeap::isEmpty() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplHeap::isEmpty() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplHeap::isEmpty() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplHeap::isEmpty() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplHeap::isEmpty() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplHeap::isEmpty() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplHeap::isEmpty() expects exactly 0 parameters, 1 given in %s on line %d +NULL + diff --git a/ext/spl/tests/SplObjectStorage_addAll_invalid_parameter.phpt b/ext/spl/tests/SplObjectStorage_addAll_invalid_parameter.phpt new file mode 100644 index 000000000..62605b1dc --- /dev/null +++ b/ext/spl/tests/SplObjectStorage_addAll_invalid_parameter.phpt @@ -0,0 +1,43 @@ +--TEST-- +Check that SplObjectStorage::addAll generate a warning and returns NULL when passed non-object param +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$data_provider = array( + array(), + true, + "string", + 12345, + 1.2345, + NULL +); + +foreach($data_provider as $input) { + + $s = new SplObjectStorage(); + + var_dump($s->addAll($input)); +} + +?> +--EXPECTF-- +Warning: SplObjectStorage::addAll() expects parameter 1 to be SplObjectStorage, array given in %s on line %d +NULL + +Warning: SplObjectStorage::addAll() expects parameter 1 to be SplObjectStorage, boolean given in %s on line %d +NULL + +Warning: SplObjectStorage::addAll() expects parameter 1 to be SplObjectStorage, %unicode_string_optional% given in %s on line %d +NULL + +Warning: SplObjectStorage::addAll() expects parameter 1 to be SplObjectStorage, integer given in %s on line %d +NULL + +Warning: SplObjectStorage::addAll() expects parameter 1 to be SplObjectStorage, double given in %s on line %d +NULL + +Warning: SplObjectStorage::addAll() expects parameter 1 to be SplObjectStorage, null given in %s on line %d +NULL + diff --git a/ext/spl/tests/SplObjectStorage_attach_invalid_parameter.phpt b/ext/spl/tests/SplObjectStorage_attach_invalid_parameter.phpt new file mode 100644 index 000000000..d984429b0 --- /dev/null +++ b/ext/spl/tests/SplObjectStorage_attach_invalid_parameter.phpt @@ -0,0 +1,20 @@ +--TEST-- +Check that SplObjectStorage::attach generates a warning and returns NULL when bad params are passed +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$s = new SplObjectStorage(); + +var_dump($s->attach(true)); +var_dump($s->attach(new stdClass, true, true)); + +?> +--EXPECTF-- +Warning: SplObjectStorage::attach() expects parameter 1 to be object, boolean given in %s on line %d +NULL + +Warning: SplObjectStorage::attach() expects at most 2 parameters, 3 given in %s on line %d +NULL + diff --git a/ext/spl/tests/SplObjectStorage_contains_invalid_parameter.phpt b/ext/spl/tests/SplObjectStorage_contains_invalid_parameter.phpt new file mode 100644 index 000000000..f52392870 --- /dev/null +++ b/ext/spl/tests/SplObjectStorage_contains_invalid_parameter.phpt @@ -0,0 +1,43 @@ +--TEST-- +Check that SplObjectStorage::contains generate a warning and returns NULL when passed non-object param +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$data_provider = array( + array(), + true, + "string", + 12345, + 1.2345, + NULL +); + +foreach($data_provider as $input) { + + $s = new SplObjectStorage(); + + var_dump($s->contains($input)); +} + +?> +--EXPECTF-- +Warning: SplObjectStorage::contains() expects parameter 1 to be object, array given in %s on line %d +NULL + +Warning: SplObjectStorage::contains() expects parameter 1 to be object, boolean given in %s on line %d +NULL + +Warning: SplObjectStorage::contains() expects parameter 1 to be object, %unicode_string_optional% given in %s on line %d +NULL + +Warning: SplObjectStorage::contains() expects parameter 1 to be object, integer given in %s on line %d +NULL + +Warning: SplObjectStorage::contains() expects parameter 1 to be object, double given in %s on line %d +NULL + +Warning: SplObjectStorage::contains() expects parameter 1 to be object, null given in %s on line %d +NULL + diff --git a/ext/spl/tests/SplObjectStorage_current_empty_storage.phpt b/ext/spl/tests/SplObjectStorage_current_empty_storage.phpt new file mode 100644 index 000000000..65fa69147 --- /dev/null +++ b/ext/spl/tests/SplObjectStorage_current_empty_storage.phpt @@ -0,0 +1,15 @@ +--TEST-- +Check that SplObjectStorage::current returns NULL when storage is empty +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$s = new SplObjectStorage(); + +var_dump($s->current()); + +?> +--EXPECT-- +NULL + diff --git a/ext/spl/tests/SplObjectStorage_detach_invalid_parameter.phpt b/ext/spl/tests/SplObjectStorage_detach_invalid_parameter.phpt new file mode 100644 index 000000000..83b79fcbf --- /dev/null +++ b/ext/spl/tests/SplObjectStorage_detach_invalid_parameter.phpt @@ -0,0 +1,43 @@ +--TEST-- +Check that SplObjectStorage::detach generate a warning and returns NULL when passed non-object param +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$data_provider = array( + array(), + true, + "string", + 12345, + 1.2345, + NULL +); + +foreach($data_provider as $input) { + + $s = new SplObjectStorage(); + + var_dump($s->detach($input)); +} + +?> +--EXPECTF-- +Warning: SplObjectStorage::detach() expects parameter 1 to be object, array given in %s on line %d +NULL + +Warning: SplObjectStorage::detach() expects parameter 1 to be object, boolean given in %s on line %d +NULL + +Warning: SplObjectStorage::detach() expects parameter 1 to be object, %unicode_string_optional% given in %s on line %d +NULL + +Warning: SplObjectStorage::detach() expects parameter 1 to be object, integer given in %s on line %d +NULL + +Warning: SplObjectStorage::detach() expects parameter 1 to be object, double given in %s on line %d +NULL + +Warning: SplObjectStorage::detach() expects parameter 1 to be object, null given in %s on line %d +NULL + diff --git a/ext/spl/tests/SplObjectStorage_getInfo_empty_storage.phpt b/ext/spl/tests/SplObjectStorage_getInfo_empty_storage.phpt new file mode 100644 index 000000000..e6c4de88c --- /dev/null +++ b/ext/spl/tests/SplObjectStorage_getInfo_empty_storage.phpt @@ -0,0 +1,15 @@ +--TEST-- +Check that SplObjectStorage::getInfo returns NULL when storage is empty +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$s = new SplObjectStorage(); + +var_dump($s->getInfo()); + +?> +--EXPECT-- +NULL + diff --git a/ext/spl/tests/SplObjectStorage_offsetGet.phpt b/ext/spl/tests/SplObjectStorage_offsetGet.phpt new file mode 100644 index 000000000..e73f6b1bd --- /dev/null +++ b/ext/spl/tests/SplObjectStorage_offsetGet.phpt @@ -0,0 +1,17 @@ +--TEST-- +Standard success for SplObjectStorage::offsetGet +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$s = new SplObjectStorage(); +$o1 = new stdClass(); +$s[$o1] = 'some_value'; + +echo $s->offsetGet($o1); + +?> +--EXPECT-- +some_value + diff --git a/ext/spl/tests/SplObjectStorage_offsetGet_invalid_parameter.phpt b/ext/spl/tests/SplObjectStorage_offsetGet_invalid_parameter.phpt new file mode 100644 index 000000000..3f8bd437e --- /dev/null +++ b/ext/spl/tests/SplObjectStorage_offsetGet_invalid_parameter.phpt @@ -0,0 +1,45 @@ +--TEST-- +Check that SplObjectStorage::offsetGet generate a warning and return NULL when passed non-object param +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$data_provider = array( + array(), + true, + "string", + 12345, + 1.2345, + NULL +); + +foreach($data_provider as $input) { + + $s = new SplObjectStorage(); + $o1 = new stdClass(); + $s[$o1] = 'some_value'; + + var_dump($s->offsetGet($input)); +} + +?> +--EXPECTF-- +Warning: SplObjectStorage::offsetGet() expects parameter 1 to be object, array given in %s on line %d +NULL + +Warning: SplObjectStorage::offsetGet() expects parameter 1 to be object, boolean given in %s on line %d +NULL + +Warning: SplObjectStorage::offsetGet() expects parameter 1 to be object, %unicode_string_optional% given in %s on line %d +NULL + +Warning: SplObjectStorage::offsetGet() expects parameter 1 to be object, integer given in %s on line %d +NULL + +Warning: SplObjectStorage::offsetGet() expects parameter 1 to be object, double given in %s on line %d +NULL + +Warning: SplObjectStorage::offsetGet() expects parameter 1 to be object, null given in %s on line %d +NULL + diff --git a/ext/spl/tests/SplObjectStorage_offsetGet_missing_object.phpt b/ext/spl/tests/SplObjectStorage_offsetGet_missing_object.phpt new file mode 100644 index 000000000..72b032c4a --- /dev/null +++ b/ext/spl/tests/SplObjectStorage_offsetGet_missing_object.phpt @@ -0,0 +1,20 @@ +--TEST-- +Check that SplObjectStorage::offsetGet throws exception when non-existing object is requested +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$s = new SplObjectStorage(); +$o1 = new stdClass(); + +try { + $s->offsetGet($o1); +} catch (UnexpectedValueException $e) { + echo $e->getMessage(); +} + +?> +--EXPECT-- +Object not found + diff --git a/ext/spl/tests/SplObjectStorage_removeAll_invalid_parameter.phpt b/ext/spl/tests/SplObjectStorage_removeAll_invalid_parameter.phpt new file mode 100644 index 000000000..ffd339869 --- /dev/null +++ b/ext/spl/tests/SplObjectStorage_removeAll_invalid_parameter.phpt @@ -0,0 +1,43 @@ +--TEST-- +Check that SplObjectStorage::removeAll generate a warning and returns NULL when passed non-object param +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$data_provider = array( + array(), + true, + "string", + 12345, + 1.2345, + NULL +); + +foreach($data_provider as $input) { + + $s = new SplObjectStorage(); + + var_dump($s->removeAll($input)); +} + +?> +--EXPECTF-- +Warning: SplObjectStorage::removeAll() expects parameter 1 to be SplObjectStorage, array given in %s on line %d +NULL + +Warning: SplObjectStorage::removeAll() expects parameter 1 to be SplObjectStorage, boolean given in %s on line %d +NULL + +Warning: SplObjectStorage::removeAll() expects parameter 1 to be SplObjectStorage, %unicode_string_optional% given in %s on line %d +NULL + +Warning: SplObjectStorage::removeAll() expects parameter 1 to be SplObjectStorage, integer given in %s on line %d +NULL + +Warning: SplObjectStorage::removeAll() expects parameter 1 to be SplObjectStorage, double given in %s on line %d +NULL + +Warning: SplObjectStorage::removeAll() expects parameter 1 to be SplObjectStorage, null given in %s on line %d +NULL + diff --git a/ext/spl/tests/SplObjectStorage_setInfo_empty_storage.phpt b/ext/spl/tests/SplObjectStorage_setInfo_empty_storage.phpt new file mode 100644 index 000000000..c8c3cd103 --- /dev/null +++ b/ext/spl/tests/SplObjectStorage_setInfo_empty_storage.phpt @@ -0,0 +1,15 @@ +--TEST-- +Check that SplObjectStorage::setInfo returns NULL when storage is empty +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$s = new SplObjectStorage(); + +var_dump($s->setInfo('some_value')); + +?> +--EXPECT-- +NULL + diff --git a/ext/spl/tests/SplObjectStorage_setInfo_invalid_parameter.phpt b/ext/spl/tests/SplObjectStorage_setInfo_invalid_parameter.phpt new file mode 100644 index 000000000..52f8f9b8e --- /dev/null +++ b/ext/spl/tests/SplObjectStorage_setInfo_invalid_parameter.phpt @@ -0,0 +1,16 @@ +--TEST-- +Check that SplObjectStorage::setInfo returns NULL when no param is passed +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$s = new SplObjectStorage(); + +var_dump($s->setInfo()); + +?> +--EXPECTF-- +Warning: SplObjectStorage::setInfo() expects exactly 1 parameter, 0 given in %s on line %d +NULL + diff --git a/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter1.phpt b/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter1.phpt new file mode 100644 index 000000000..dcf43e21f --- /dev/null +++ b/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter1.phpt @@ -0,0 +1,27 @@ +--TEST-- +Check that SplObjectStorage::unserialize returns NULL when non-string param is passed +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$data_provider = array( + array(), + new stdClass(), +); + +foreach($data_provider as $input) { + + $s = new SplObjectStorage(); + + var_dump($s->unserialize($input)); +} + +?> +--EXPECTF-- +Warning: SplObjectStorage::unserialize() expects parameter 1 to be %binary_string_optional%, array given in %s on line %d +NULL + +Warning: SplObjectStorage::unserialize() expects parameter 1 to be %binary_string_optional%, object given in %s on line %d +NULL + diff --git a/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter2.phpt b/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter2.phpt new file mode 100644 index 000000000..be2bb331b --- /dev/null +++ b/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter2.phpt @@ -0,0 +1,34 @@ +--TEST-- +Check that SplObjectStorage::unserialize throws exception when numeric value passed +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$data_provider = array( + 12345, + 1.2345, + PHP_INT_MAX, + 'x:rubbish', // rubbish after the 'x:' prefix + 'x:i:2;O:8:"stdClass":0:{},s:5:"value";;m:a:0:{}', +); + +foreach($data_provider as $input) { + + $s = new SplObjectStorage(); + + try { + $s->unserialize($input); + } catch(UnexpectedValueException $e) { + echo $e->getMessage() . PHP_EOL; + } +} + +?> +--EXPECTF-- +Error at offset %d of %d bytes +Error at offset %d of %d bytes +Error at offset %d of %d bytes +Error at offset %d of %d bytes +Error at offset %d of %d bytes + diff --git a/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter3.phpt b/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter3.phpt new file mode 100644 index 000000000..4c2dd75e1 --- /dev/null +++ b/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter3.phpt @@ -0,0 +1,19 @@ +--TEST-- +Check that SplObjectStorage::unserialize throws exception when NULL passed +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$s = new SplObjectStorage(); + +try { + $s->unserialize(NULL); +} catch(UnexpectedValueException $e) { + echo $e->getMessage(); +} + +?> +--EXPECTF-- +Empty serialized string cannot be empty + diff --git a/ext/spl/tests/SplPriorityQueue_extract_invalid_parameter.phpt b/ext/spl/tests/SplPriorityQueue_extract_invalid_parameter.phpt new file mode 100644 index 000000000..7dda782b9 --- /dev/null +++ b/ext/spl/tests/SplPriorityQueue_extract_invalid_parameter.phpt @@ -0,0 +1,47 @@ +--TEST-- +Check that SplPriorityQueue::extract generate a warning and returns NULL when param passed +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$data_provider = array( + new stdClass, + array(), + true, + "string", + 12345, + 1.2345, + NULL +); + +foreach($data_provider as $input) { + + $h = new SplPriorityQueue(); + + var_dump($h->extract($input)); +} + +?> +--EXPECTF-- +Warning: SplPriorityQueue::extract() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplPriorityQueue::extract() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplPriorityQueue::extract() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplPriorityQueue::extract() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplPriorityQueue::extract() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplPriorityQueue::extract() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: SplPriorityQueue::extract() expects exactly 0 parameters, 1 given in %s on line %d +NULL + diff --git a/ext/spl/tests/SplPriorityQueue_insert_invalid_parameter.phpt b/ext/spl/tests/SplPriorityQueue_insert_invalid_parameter.phpt new file mode 100644 index 000000000..7d7b58935 --- /dev/null +++ b/ext/spl/tests/SplPriorityQueue_insert_invalid_parameter.phpt @@ -0,0 +1,16 @@ +--TEST-- +Check that SplPriorityQueue::insert generate a warning and returns NULL when rubbish params are passed +--CREDITS-- +PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) +--FILE-- +<?php + +$h = new SplPriorityQueue(); + +var_dump($h->insert(NULL)); + +?> +--EXPECTF-- +Warning: SplPriorityQueue::insert() expects exactly 2 parameters, 1 given in %s on line %d +NULL + diff --git a/ext/spl/tests/SplQueue_setIteratorMode.phpt b/ext/spl/tests/SplQueue_setIteratorMode.phpt new file mode 100644 index 000000000..172a1d97a --- /dev/null +++ b/ext/spl/tests/SplQueue_setIteratorMode.phpt @@ -0,0 +1,15 @@ +--TEST-- +Check that SplQueue can't be set to LIFO +--CREDITS-- +Rob Knight <themanhimself@robknight.org.uk> PHPNW Test Fest 2009 +--FILE-- +<?php +$queue = new SplQueue(); +try { + $queue->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO); +} catch (Exception $e) { + echo $e->getMessage(); +} +?> +--EXPECTF-- +Iterators' LIFO/FIFO modes for SplStack/SplQueue objects are frozen diff --git a/ext/spl/tests/SplQueue_setIteratorMode_param_lifo.phpt b/ext/spl/tests/SplQueue_setIteratorMode_param_lifo.phpt new file mode 100644 index 000000000..c3071f239 --- /dev/null +++ b/ext/spl/tests/SplQueue_setIteratorMode_param_lifo.phpt @@ -0,0 +1,19 @@ +--TEST-- +SplQueue setIteratorMode to LIFO produces fail condition in try/catch +--CREDITS-- +PHPNW Test Fest 2009 - Jeremy Coates jeremy@phpnw.org.uk +--FILE-- +<?php + +try { + + $dll = new SplQueue(); + $dll->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO); + +} catch (Exception $e) { + echo $e->getMessage(); +} + +?> +--EXPECT-- +Iterators' LIFO/FIFO modes for SplStack/SplQueue objects are frozen diff --git a/ext/spl/tests/SplStack_setIteratorMode.phpt b/ext/spl/tests/SplStack_setIteratorMode.phpt new file mode 100644 index 000000000..d70105e03 --- /dev/null +++ b/ext/spl/tests/SplStack_setIteratorMode.phpt @@ -0,0 +1,15 @@ +--TEST-- +Check that SplStack can't be set to FIFO +--CREDITS-- +Rob Knight <themanhimself@robknight.org.uk> PHPNW Test Fest 2009 +--FILE-- +<?php +$stack = new SplStack(); +try { + $stack->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO); +} catch (Exception $e) { + echo $e->getMessage(); +} +?> +--EXPECTF-- +Iterators' LIFO/FIFO modes for SplStack/SplQueue objects are frozen diff --git a/ext/spl/tests/arrayObject_magicMethods6.phpt b/ext/spl/tests/arrayObject_magicMethods6.phpt index 40280212d..90781fa1d 100644 --- a/ext/spl/tests/arrayObject_magicMethods6.phpt +++ b/ext/spl/tests/arrayObject_magicMethods6.phpt @@ -143,11 +143,8 @@ object(UsesMagic)#2 (2) { } --> isset existent, non-existent and dynamic: -In UsesMagic::__isset(a) bool(true) -In UsesMagic::__isset(nonexistent) bool(false) -In UsesMagic::__isset(dynamic) bool(true) Original wrapped object: object(C)#1 (5) { diff --git a/ext/spl/tests/bug38325.phpt b/ext/spl/tests/bug38325.phpt index 959a451d2..ddb2829da 100644 --- a/ext/spl/tests/bug38325.phpt +++ b/ext/spl/tests/bug38325.phpt @@ -3,7 +3,7 @@ Bug #38325 (spl_autoload_register() gaves wrong line for "class not found") --FILE-- <?php spl_autoload_register(); -new Foo(); +new ThisClassDoesNotExistEverFoo(); ?> --EXPECTF-- -Fatal error: spl_autoload(): Class Foo could not be loaded in %s on line 3 +Fatal error: spl_autoload(): Class ThisClassDoesNotExistEverFoo could not be loaded in %s on line 3 diff --git a/ext/spl/tests/bug45622b.phpt b/ext/spl/tests/bug45622b.phpt new file mode 100644 index 000000000..9d4939211 --- /dev/null +++ b/ext/spl/tests/bug45622b.phpt @@ -0,0 +1,33 @@ +--TEST-- +Ensure fix to bug45622 doesn't cause __isset() to be called when ArrayObject::ARRAY_AS_PROPS is used. +--FILE-- +<?php +class UsesMagic extends ArrayObject { + function __get($n) { echo "In " . __METHOD__ . "!\n"; } + function __set($n, $v) { echo "In " . __METHOD__ . "!\n"; } + function __isset($n) { echo "In " . __METHOD__ . "!\n"; } + function __unset($n) { echo "In " . __METHOD__ . "!\n"; } +} +$ao = new UsesMagic(array(), ArrayObject::ARRAY_AS_PROPS); + +echo "Doesn't trigger __get.\n"; +echo $ao->prop1; + +echo "Doesn't trigger __set.\n"; +$ao->prop2 = 'foo'; + +echo "Doesn't trigger __unset.\n"; +unset($ao->prop3); + +echo "Shouldn't trigger __isset.\n"; +isset($ao->prop4); +?> +--EXPECTF-- +Doesn't trigger __get. + +Notice: Undefined index: prop1 in %s on line 11 +Doesn't trigger __set. +Doesn't trigger __unset. + +Notice: Undefined index: prop3 in %s on line 17 +Shouldn't trigger __isset.
\ No newline at end of file diff --git a/ext/spl/tests/bug47534.phpt b/ext/spl/tests/bug47534.phpt new file mode 100644 index 000000000..d221c23fd --- /dev/null +++ b/ext/spl/tests/bug47534.phpt @@ -0,0 +1,14 @@ +--TEST-- +SPL: RecursiveDirectoryIterator bug 47534 +--FILE-- +<?php +$it1 = new RecursiveDirectoryIterator(dirname(__FILE__), FileSystemIterator::CURRENT_AS_PATHNAME); +$it1->rewind(); +echo gettype($it1->current())."\n"; + +$it2 = new RecursiveDirectoryIterator(dirname(__FILE__)); +$it2->rewind(); +echo gettype($it2->current())."\n"; +--EXPECT-- +string +object diff --git a/ext/spl/tests/bug48023.phpt b/ext/spl/tests/bug48023.phpt new file mode 100644 index 000000000..ed0ff9e35 --- /dev/null +++ b/ext/spl/tests/bug48023.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #48023 (spl_autoload_register didn't addref closures) +--FILE-- +<?php +spl_autoload_register(function(){}); + +new Foo; + +?> +===DONE=== +--EXPECTF-- +Fatal error: Class 'Foo' not found in %s on line %d diff --git a/ext/spl/tests/bug48493.phpt b/ext/spl/tests/bug48493.phpt new file mode 100644 index 000000000..d0be7f8ec --- /dev/null +++ b/ext/spl/tests/bug48493.phpt @@ -0,0 +1,26 @@ +--TEST-- +SPL: Bug #48493 spl_autoload_unregister() can't handle prepended functions +--FILE-- +<?php +function autoload1() {} + +function autoload2() {} + +spl_autoload_register('autoload2'); +spl_autoload_register('autoload1', true, true); +var_dump(spl_autoload_functions()); + +spl_autoload_unregister('autoload2'); +var_dump(spl_autoload_functions()); +?> +--EXPECT-- +array(2) { + [0]=> + string(9) "autoload1" + [1]=> + string(9) "autoload2" +} +array(1) { + [0]=> + string(9) "autoload1" +} diff --git a/ext/spl/tests/dit_003.phpt b/ext/spl/tests/dit_003.phpt index 7a38e7380..4ffc2921e 100755 --- a/ext/spl/tests/dit_003.phpt +++ b/ext/spl/tests/dit_003.phpt @@ -3,7 +3,7 @@ SPL: FilesystemIterator and foreach --FILE-- <?php $count = 0; -foreach(new FilesystemIterator('CVS') as $ent) +foreach(new FilesystemIterator(__DIR__) as $ent) { ++$count; } diff --git a/ext/spl/tests/dllist_010.phpt b/ext/spl/tests/dllist_010.phpt new file mode 100644 index 000000000..7e389559e --- /dev/null +++ b/ext/spl/tests/dllist_010.phpt @@ -0,0 +1,33 @@ +--TEST-- +SPL: DoublyLinkedList: prev +--FILE-- +<?php +$dll = new SplDoublyLinkedList(); +$dll->push(1); +$dll->push(2); +$dll->push(3); +$dll->push(4); + + +$dll->rewind(); +$dll->prev(); +var_dump($dll->current()); +$dll->rewind(); +var_dump($dll->current()); +$dll->next(); +var_dump($dll->current()); +$dll->next(); +$dll->next(); +var_dump($dll->current()); +$dll->prev(); +var_dump($dll->current()); + +?> +===DONE=== +--EXPECT-- +NULL +int(1) +int(2) +int(4) +int(3) +===DONE=== diff --git a/ext/spl/tests/dllist_011.phpt b/ext/spl/tests/dllist_011.phpt new file mode 100644 index 000000000..b9be87255 --- /dev/null +++ b/ext/spl/tests/dllist_011.phpt @@ -0,0 +1,13 @@ +--TEST-- +SPL: DoublyLinkedList: prev +--FILE-- +<?php +$dll = new SplDoublyLinkedList(); +$dll->rewind(); +$dll->prev(); +var_dump($dll->current()); +?> +===DONE=== +--EXPECT-- +NULL +===DONE=== diff --git a/ext/spl/tests/dllist_memleak.phpt b/ext/spl/tests/dllist_memleak.phpt new file mode 100644 index 000000000..9bae68bf2 --- /dev/null +++ b/ext/spl/tests/dllist_memleak.phpt @@ -0,0 +1,24 @@ +--TEST-- +SPL: DoublyLinkedList: memory leak when iterator pointer isn't at the last element +--FILE-- +<?php +$dll = new SplDoublyLinkedList(); +$dll->push(1); +$dll->push(2); +$dll->push(3); +$dll->push(4); + + +$dll->rewind(); +echo $dll->current()."\n"; +$dll->next(); +$dll->next(); +echo $dll->current()."\n"; + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +1 +3 +===DONE=== diff --git a/ext/spl/tests/heap_corruption.phpt b/ext/spl/tests/heap_corruption.phpt new file mode 100644 index 000000000..17f0ac8c2 --- /dev/null +++ b/ext/spl/tests/heap_corruption.phpt @@ -0,0 +1,62 @@ +--TEST--
+SPL: SplHeap - heap corruption via compare exception (with top element deletion)
+--CREDITS--
+Mike Sullivan <mikesul@php.net>
+#TestFest 2009 (London)
+--FILE--
+<?php
+
+class myHeap extends SplHeap
+{
+ public $allow_compare = true;
+
+ public function compare($v1, $v2)
+ {
+ if ($this->allow_compare == true)
+ {
+ if ($v1 > $v2)
+ {
+ return 1;
+ }
+ else if ($v1 < $v2)
+ {
+ return -1;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ else
+ {
+ throw new Exception('Compare exception');
+ }
+ }
+}
+
+$heap = new myHeap();
+$heap->insert(1);
+$heap->insert(2);
+$heap->insert(3);
+$heap->insert(4);
+
+$heap->allow_compare = false;
+
+try {
+ $heap->extract();
+}
+catch (Exception $e) {
+ echo "Compare Exception: " . $e->getMessage() . PHP_EOL;
+}
+
+try {
+ $heap->top();
+}
+catch (Exception $e) {
+ echo "Corruption Exception: " . $e->getMessage() . PHP_EOL;
+}
+
+?>
+--EXPECT--
+Compare Exception: Compare exception
+Corruption Exception: Heap is corrupted, heap properties are no longer ensured.
\ No newline at end of file diff --git a/ext/spl/tests/heap_current_variation_001.phpt b/ext/spl/tests/heap_current_variation_001.phpt new file mode 100644 index 000000000..a514fb898 --- /dev/null +++ b/ext/spl/tests/heap_current_variation_001.phpt @@ -0,0 +1,22 @@ +--TEST--
+SPL: SplHeap::current - get current value from empty heap
+--CREDITS--
+Mike Sullivan <mikesul@php.net>
+#TestFest 2009 (London)
+--FILE--
+<?php
+
+class myHeap extends SplHeap
+{
+ public function compare($v1, $v2)
+ {
+ throw new Exception('');
+ }
+}
+
+$heap = new myHeap();
+var_dump($heap->current());
+
+?>
+--EXPECT--
+NULL
\ No newline at end of file diff --git a/ext/spl/tests/heap_isempty_variation_001.phpt b/ext/spl/tests/heap_isempty_variation_001.phpt new file mode 100644 index 000000000..78deaa892 --- /dev/null +++ b/ext/spl/tests/heap_isempty_variation_001.phpt @@ -0,0 +1,16 @@ +--TEST--
+SPL: SplHeap: isEmpty argument variation.
+--FILE--
+<?php
+class SplHeap2 extends SplHeap{
+
+ public function compare() {
+ return -parent::compare();
+ }
+}
+
+$h = new SplHeap2;
+$h->isEmpty(1);
+?>
+--EXPECTF--
+Warning: SplHeap::isEmpty() expects exactly 0 parameters, 1 given in %s
diff --git a/ext/spl/tests/heap_it_current_empty.phpt b/ext/spl/tests/heap_it_current_empty.phpt new file mode 100644 index 000000000..24230dbee --- /dev/null +++ b/ext/spl/tests/heap_it_current_empty.phpt @@ -0,0 +1,12 @@ +--TEST-- +SPL: SplHeap current, check looping through an empty heap gives you no values +--CREDITS-- +Mark Schaschke (mark@fractalturtle.com) +TestFest London May 2009 +--FILE-- +<?php +$h = new SplMinHeap(); + +foreach ($h as $val) { echo 'FAIL'; } +?> +--EXPECT-- diff --git a/ext/spl/tests/heap_top_variation_001.phpt b/ext/spl/tests/heap_top_variation_001.phpt new file mode 100644 index 000000000..9953cf9ad --- /dev/null +++ b/ext/spl/tests/heap_top_variation_001.phpt @@ -0,0 +1,14 @@ +--TEST-- +SPL: SplHeap top, illegal number of args +--CREDITS-- +Mark Schaschke (mark@fractalturtle.com) +TestFest London May 2009 +--FILE-- +<?php +$h = new SplMinHeap(); +$h->insert(5); +// top doesn't take any args, lets see what happens if we give it one +$h->top('bogus'); +?> +--EXPECTF-- +Warning: SplHeap::top() expects exactly 0 parameters, 1 given in %s diff --git a/ext/spl/tests/heap_top_variation_002.phpt b/ext/spl/tests/heap_top_variation_002.phpt new file mode 100644 index 000000000..cd6a8d0ad --- /dev/null +++ b/ext/spl/tests/heap_top_variation_002.phpt @@ -0,0 +1,31 @@ +--TEST-- +SPL: SplHeap top, corrupted heap +--CREDITS-- +Mark Schaschke (mark@fractalturtle.com) +TestFest London May 2009 +--FILE-- +<?php +// override heap to force corruption by throwing exception in compare +class SplMinHeap2 extends SplMinHeap { + public function compare($a, $b) { + throw new Exception('Corrupt heap'); + } +} + +$h = new SplMinHeap2(); + +// insert 2 elements to hit our overridden compare +$h->insert(4); +try { + $h->insert(5); +} catch (Exception $e) {} + +// call top, should fail with corrupted heap +try { + $h->top(); +} catch (Exception $e) { + echo $e->getMessage(); +} +?> +--EXPECTF-- +Heap is corrupted, heap properties are no longer ensured. diff --git a/ext/spl/tests/heap_top_variation_003.phpt b/ext/spl/tests/heap_top_variation_003.phpt new file mode 100644 index 000000000..7a91a9c00 --- /dev/null +++ b/ext/spl/tests/heap_top_variation_003.phpt @@ -0,0 +1,16 @@ +--TEST-- +SPL: SplHeap top of empty heap +--CREDITS-- +Mark Schaschke (mark@fractalturtle.com) +TestFest London May 2009 +--FILE-- +<?php +$h = new SplMinHeap(); +try { + $h->top(); +} catch (Exception $e) { + echo $e->getMessage(); +} +?> +--EXPECTF-- +Can't peek at an empty heap diff --git a/ext/spl/tests/iterator_count.phpt b/ext/spl/tests/iterator_count.phpt new file mode 100644 index 000000000..1db568d14 --- /dev/null +++ b/ext/spl/tests/iterator_count.phpt @@ -0,0 +1,26 @@ +--TEST--
+SPL: iterator_count() exceptions test
+--CREDITS--
+Lance Kesson jac_kesson@hotmail.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+$array=array('a','b');
+
+$iterator = new ArrayIterator($array);
+
+iterator_count();
+
+
+iterator_count($iterator,'1');
+
+iterator_count('1');
+
+
+?>
+--EXPECTF--
+Warning: iterator_count() expects exactly 1 parameter, 0 given in %s
+
+Warning: iterator_count() expects exactly 1 parameter, 2 given in %s
+
+Catchable fatal error: Argument 1 passed to iterator_count() must implement interface Traversable, %unicode_string_optional% given %s
diff --git a/ext/spl/tests/iterator_to_array.phpt b/ext/spl/tests/iterator_to_array.phpt new file mode 100644 index 000000000..574e050b9 --- /dev/null +++ b/ext/spl/tests/iterator_to_array.phpt @@ -0,0 +1,25 @@ +--TEST--
+SPL: iterator_to_array() exceptions test
+--CREDITS--
+Lance Kesson jac_kesson@hotmail.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+$array=array('a','b');
+
+$iterator = new ArrayIterator($array);
+
+iterator_to_array();
+
+
+iterator_to_array($iterator,'test','test');
+
+iterator_to_array('test','test');
+
+?>
+--EXPECTF--
+Warning: iterator_to_array() expects at least 1 parameter, 0 given in %s
+
+Warning: iterator_to_array() expects at most 2 parameters, 3 given in %s
+
+Catchable fatal error: Argument 1 passed to iterator_to_array() must implement interface Traversable, %unicode_string_optional% given %s
diff --git a/ext/spl/tests/limititerator_seek.phpt b/ext/spl/tests/limititerator_seek.phpt new file mode 100644 index 000000000..a59a49bee --- /dev/null +++ b/ext/spl/tests/limititerator_seek.phpt @@ -0,0 +1,18 @@ +--TEST-- +SPL: LimitIterator seek() arguments +--CREDITS-- +Roshan Abraham (roshanabrahams@gmail.com) +TestFest London May 2009 +--FILE-- +<?php + +$a = array(1,2,3); +$lt = new LimitIterator(new ArrayIterator($a)); + +$lt->seek(1,1); // Should throw a warning as seek expects only 1 argument + +?> +--EXPECTF-- + +Warning: LimitIterator::seek() expects exactly 1 parameter, 2 given in %s on line %d + diff --git a/ext/spl/tests/pqueue_compare_basic.phpt b/ext/spl/tests/pqueue_compare_basic.phpt new file mode 100644 index 000000000..1544add46 --- /dev/null +++ b/ext/spl/tests/pqueue_compare_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +SPL: SplPriorityQueue: test compare +--CREDITS-- +Mark Schaschke (mark@fractalturtle.com) +TestFest London May 2009 +--FILE-- +<?php +$h = new SplPriorityQueue(); +var_dump($h->compare(4, 5) < 0); +var_dump($h->compare(5, 5) == 0); +var_dump($h->compare(5, 4) > 0); +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +bool(true) +bool(true) +bool(true) +===DONE=== diff --git a/ext/spl/tests/pqueue_compare_error.phpt b/ext/spl/tests/pqueue_compare_error.phpt new file mode 100644 index 000000000..610be2a56 --- /dev/null +++ b/ext/spl/tests/pqueue_compare_error.phpt @@ -0,0 +1,19 @@ +--TEST-- +SPL: Priority queue compare, illegal number of args +--CREDITS-- +Mark Schaschke (mark@fractalturtle.com) +TestFest London May 2009 +--FILE-- +<?php +$h = new SplPriorityQueue(); +$h->compare(); +$h->compare(1); +$h->compare(1, 2, 3); +?> +--EXPECTF-- +Warning: SplPriorityQueue::compare() expects exactly 2 parameters, 0 given in %s + +Warning: SplPriorityQueue::compare() expects exactly 2 parameters, 1 given in %s + +Warning: SplPriorityQueue::compare() expects exactly 2 parameters, 3 given in %s + diff --git a/ext/spl/tests/pqueue_current_error.phpt b/ext/spl/tests/pqueue_current_error.phpt new file mode 100644 index 000000000..7fdf0af5e --- /dev/null +++ b/ext/spl/tests/pqueue_current_error.phpt @@ -0,0 +1,12 @@ +--TEST-- +SPL: SplPriorityQueue current on empty queue should give null +--CREDITS-- +Mark Schaschke (mark@fractalturtle.com) +TestFest London May 2009 +--FILE-- +<?php +$h = new SplPriorityQueue(); +var_dump($h->current()); +?> +--EXPECT-- +NULL diff --git a/ext/spl/tests/recursive_tree_iterator_setprefixpart.phpt b/ext/spl/tests/recursive_tree_iterator_setprefixpart.phpt new file mode 100644 index 000000000..f5af0dd4a --- /dev/null +++ b/ext/spl/tests/recursive_tree_iterator_setprefixpart.phpt @@ -0,0 +1,32 @@ +--TEST--
+SPL: RecursiveTreeIterator::setPrefixPart() Test arguments
+--CREDITS--
+Roshan Abraham (roshanabrahams@gmail.com)
+TestFest London May 2009
+--FILE--
+<?php
+
+$arr = array(
+ "a" => array("b")
+);
+
+$it = new RecursiveArrayIterator($arr);
+$it = new RecursiveTreeIterator($it);
+
+$it->setPrefixPart(1); // Should throw a warning as setPrefixPart expects 2 arguments
+
+$a = new stdClass();
+$it->setPrefixPart($a, 1); // Should throw a warning as setPrefixPart expects argument 1 to be long integer
+
+$it->setPrefixPart(1, $a); // Should throw a warning as setPrefixPart expects argument 2 to be a string
+
+
+?>
+===DONE===
+--EXPECTF--
+Warning: RecursiveTreeIterator::setPrefixPart() expects exactly 2 parameters, 1 given in %s on line %d
+
+Warning: RecursiveTreeIterator::setPrefixPart() expects parameter 1 to be long, object given in %s on line %d
+
+Warning: RecursiveTreeIterator::setPrefixPart() expects parameter 2 to be %binary_string_optional%, object given in %s on line %d
+===DONE===
diff --git a/ext/spl/tests/recursiveiteratoriterator_beginiteration_basic.phpt b/ext/spl/tests/recursiveiteratoriterator_beginiteration_basic.phpt new file mode 100644 index 000000000..c9476e0e5 --- /dev/null +++ b/ext/spl/tests/recursiveiteratoriterator_beginiteration_basic.phpt @@ -0,0 +1,32 @@ +--TEST-- +SPL: RecursiveIteratorIterator::beginIteration() is called by RecursiveIteratorIterator::rewind() +--CREDITS-- +Matt Raines matt@raines.me.uk +#testfest London 2009-05-09 +--FILE-- +<?php +$sample_array = array(1, 2); +$sub_iterator = new RecursiveArrayIterator($sample_array); + +$iterator = new RecursiveIteratorIterator($sub_iterator); +foreach ($iterator as $element) { + var_dump($element); +} + +class SkipsFirstElementRecursiveIteratorIterator extends RecursiveIteratorIterator { + public function beginIteration() { + echo "::beginIteration() was invoked\n"; + $this->next(); + } +} +$iterator = new SkipsFirstElementRecursiveIteratorIterator($sub_iterator); +foreach ($iterator as $element) { + var_dump($element); +} +?> +--EXPECT-- +int(1) +int(2) +::beginIteration() was invoked +int(2) + diff --git a/ext/spl/tests/recursiveiteratoriterator_enditeration_basic.phpt b/ext/spl/tests/recursiveiteratoriterator_enditeration_basic.phpt new file mode 100644 index 000000000..0355401f2 --- /dev/null +++ b/ext/spl/tests/recursiveiteratoriterator_enditeration_basic.phpt @@ -0,0 +1,32 @@ +--TEST-- +SPL: RecursiveIteratorIterator::endIteration() is called when ::valid() first returns false +--CREDITS-- +Matt Raines matt@raines.me.uk +#testfest London 2009-05-09 +--FILE-- +<?php +$sample_array = array(1, 2); +$sub_iterator = new RecursiveArrayIterator($sample_array); + +$iterator = new RecursiveIteratorIterator($sub_iterator); +foreach ($iterator as $element) { + var_dump($element); +} + +class EndIterationRecursiveIteratorIterator extends RecursiveIteratorIterator { + public function endIteration() { + echo "::endIteration() was invoked\n"; + } +} +$iterator = new EndIterationRecursiveIteratorIterator($sub_iterator); +foreach ($iterator as $element) { + var_dump($element); +} +?> +--EXPECT-- +int(1) +int(2) +int(1) +int(2) +::endIteration() was invoked + diff --git a/ext/spl/tests/recursiveiteratoriterator_getsubiterator_basic.phpt b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_basic.phpt new file mode 100644 index 000000000..5d1c958d9 --- /dev/null +++ b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_basic.phpt @@ -0,0 +1,20 @@ +--TEST-- +SPL: RecursiveIteratorIterator::getSubIterator() returns iterator passed in constructor +--CREDITS-- +Matt Raines matt@raines.me.uk +#testfest London 2009-05-09 +--FILE-- +<?php +$sample_array = array(1, 2, array(3, 4)); + +$sub_iterator = new RecursiveArrayIterator($sample_array); +$not_sub_iterator = new RecursiveArrayIterator($sample_array); +$iterator = new RecursiveIteratorIterator($sub_iterator); + +var_dump($iterator->getSubIterator() === $sub_iterator); +var_dump($iterator->getSubIterator() === $not_sub_iterator); +?> +--EXPECT-- +bool(true) +bool(false) + diff --git a/ext/spl/tests/recursiveiteratoriterator_getsubiterator_error.phpt b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_error.phpt new file mode 100644 index 000000000..760082f6b --- /dev/null +++ b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_error.phpt @@ -0,0 +1,15 @@ +--TEST-- +SPL: RecursiveIteratorIterator::getSubIterator() expects at most 1 parameter +--CREDITS-- +Matt Raines matt@raines.me.uk +#testfest London 2009-05-09 +--FILE-- +<?php +$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator(array())); +$iterator->getSubIterator(); +$iterator->getSubIterator(0); +$iterator->getSubIterator(0, 0); +?> +--EXPECTF-- +Warning: RecursiveIteratorIterator::getSubIterator() expects at most 1 parameter, 2 given in %s on line 5 + diff --git a/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation.phpt b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation.phpt new file mode 100644 index 000000000..a7b84c4bc --- /dev/null +++ b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation.phpt @@ -0,0 +1,42 @@ +--TEST-- +SPL: RecursiveIteratorIterator::getSubIterator() returns different iterators depending on the current element +--CREDITS-- +Matt Raines matt@raines.me.uk +#testfest London 2009-05-09 +--FILE-- +<?php +$sample_array = array(1, 2, array(3, 4)); + +$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($sample_array)); + +$iterator->next(); +$iterator->next(); +var_dump(get_class($iterator->getSubIterator())); +var_dump($iterator->getSubIterator()->getArrayCopy()); +$iterator->next(); +var_dump(get_class($iterator->getSubIterator())); +var_dump($iterator->getSubIterator()->getArrayCopy()); +?> +--EXPECTF-- +%unicode|string%(22) "RecursiveArrayIterator" +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } +} +%unicode|string%(22) "RecursiveArrayIterator" +array(2) { + [0]=> + int(3) + [1]=> + int(4) +} + diff --git a/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation_002.phpt b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation_002.phpt new file mode 100644 index 000000000..aac4e65bb --- /dev/null +++ b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation_002.phpt @@ -0,0 +1,20 @@ +--TEST-- +SPL: RecursiveIteratorIterator::getSubIterator() returns NULL if there's no current element +--CREDITS-- +Matt Raines matt@raines.me.uk +#testfest London 2009-05-09 +--FILE-- +<?php +$sample_array = array(1); + +$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($sample_array)); + +$iterator->next(); +var_dump(is_null($iterator->getSubIterator())); +$iterator->next(); +var_dump(is_null($iterator->getSubIterator())); +?> +--EXPECT-- +bool(false) +bool(false) + diff --git a/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation_003.phpt b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation_003.phpt new file mode 100644 index 000000000..ff1884039 --- /dev/null +++ b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation_003.phpt @@ -0,0 +1,42 @@ +--TEST-- +SPL: RecursiveIteratorIterator::getSubIterator() with explicit level parameter +--CREDITS-- +Matt Raines matt@raines.me.uk +#testfest London 2009-05-09 +--FILE-- +<?php +$sample_array = array(1, 2, array(3, 4)); + +$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($sample_array)); + +$iterator->next(); +$iterator->next(); +$iterator->next(); +var_dump($iterator->getSubIterator(-1)); +var_dump($iterator->getSubIterator(0)->getArrayCopy()); +var_dump($iterator->getSubIterator(1)->getArrayCopy()); +var_dump($iterator->getSubIterator(2)); +?> +--EXPECT-- +NULL +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } +} +array(2) { + [0]=> + int(3) + [1]=> + int(4) +} +NULL + diff --git a/ext/spl/tests/recursiveiteratoriterator_nextelement_basic.phpt b/ext/spl/tests/recursiveiteratoriterator_nextelement_basic.phpt new file mode 100644 index 000000000..0bf4f198f --- /dev/null +++ b/ext/spl/tests/recursiveiteratoriterator_nextelement_basic.phpt @@ -0,0 +1,39 @@ +--TEST-- +SPL: RecursiveIteratorIterator::nextElement() is called when the next element is ready +--CREDITS-- +Matt Raines matt@raines.me.uk +#testfest London 2009-05-09 +--FILE-- +<?php +$sample_array = array(1, 2, array(3, 4)); +$sub_iterator = new RecursiveArrayIterator($sample_array); + +$iterator = new RecursiveIteratorIterator($sub_iterator); +foreach ($iterator as $element) { + var_dump($element); +} + +class NextElementRecursiveIteratorIterator extends RecursiveIteratorIterator { + public function nextElement() { + echo "::nextElement() was invoked\n"; + } +} +$iterator = new NextElementRecursiveIteratorIterator($sub_iterator); +foreach ($iterator as $element) { + var_dump($element); +} +?> +--EXPECT-- +int(1) +int(2) +int(3) +int(4) +::nextElement() was invoked +int(1) +::nextElement() was invoked +int(2) +::nextElement() was invoked +int(3) +::nextElement() was invoked +int(4) + diff --git a/ext/spl/tests/regexiterator_getpregflags.phpt b/ext/spl/tests/regexiterator_getpregflags.phpt new file mode 100644 index 000000000..db961538d --- /dev/null +++ b/ext/spl/tests/regexiterator_getpregflags.phpt @@ -0,0 +1,33 @@ +--TEST--
+SPL: RegexIterator::getPregFlags()
+--CREDITS--
+Lance Kesson jac_kesson@hotmail.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+
+class myIterator implements Iterator {
+
+function current (){}
+function key ( ){}
+function next ( ){}
+function rewind ( ){}
+function valid ( ){}
+
+
+}
+
+class TestRegexIterator extends RegexIterator{}
+
+$rege = '/^a/';
+
+
+$r = new TestRegexIterator(new myIterator, $rege);
+
+$r->setPregFlags(PREG_OFFSET_CAPTURE);
+
+echo is_long($r->getPregFlags());
+
+?>
+--EXPECTF--
+1
\ No newline at end of file diff --git a/ext/spl/tests/regexiterator_setflags_exception.phpt b/ext/spl/tests/regexiterator_setflags_exception.phpt new file mode 100644 index 000000000..66c82b159 --- /dev/null +++ b/ext/spl/tests/regexiterator_setflags_exception.phpt @@ -0,0 +1,35 @@ +--TEST--
+SPL: RegexIterator::setFlags() exceptions test
+--CREDITS--
+Lance Kesson jac_kesson@hotmail.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+
+class myIterator implements Iterator {
+
+function current (){}
+function key ( ){}
+function next ( ){}
+function rewind ( ){}
+function valid ( ){}
+
+
+}
+
+class TestRegexIterator extends RegexIterator{}
+
+$rege = '/^a/';
+
+
+$r = new TestRegexIterator(new myIterator, $rege);
+
+try{
+ $r->setFlags();
+}catch (Exception $e) {
+ echo $e->getMessage();
+}
+
+?>
+--EXPECTF--
+Warning: RegexIterator::setFlags() expects exactly 1 parameter, 0 given in %s
\ No newline at end of file diff --git a/ext/spl/tests/regexiterator_setpregflags.phpt b/ext/spl/tests/regexiterator_setpregflags.phpt new file mode 100644 index 000000000..a14da6164 --- /dev/null +++ b/ext/spl/tests/regexiterator_setpregflags.phpt @@ -0,0 +1,34 @@ +--TEST--
+SPL: RegexIterator::setPregFlags()
+--CREDITS--
+Lance Kesson jac_kesson@hotmail.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+
+class myIterator implements Iterator {
+
+function current (){}
+function key ( ){}
+function next ( ){}
+function rewind ( ){}
+function valid ( ){}
+
+
+}
+
+class TestRegexIterator extends RegexIterator{}
+
+$rege = '/^a/';
+
+
+$r = new TestRegexIterator(new myIterator, $rege);
+
+$r->setPregFlags(PREG_OFFSET_CAPTURE);
+
+echo $r->getPregFlags();
+
+
+?>
+--EXPECTF--
+256
\ No newline at end of file diff --git a/ext/spl/tests/regexiterator_setpregflags_exception.phpt b/ext/spl/tests/regexiterator_setpregflags_exception.phpt new file mode 100644 index 000000000..489505ce5 --- /dev/null +++ b/ext/spl/tests/regexiterator_setpregflags_exception.phpt @@ -0,0 +1,36 @@ +--TEST--
+SPL: RegexIterator::getPregFlags() exception test
+--CREDITS--
+Lance Kesson jac_kesson@hotmail.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+
+class myIterator implements Iterator {
+
+function current (){}
+function key ( ){}
+function next ( ){}
+function rewind ( ){}
+function valid ( ){}
+
+
+}
+
+class TestRegexIterator extends RegexIterator{}
+
+$rege = '/^a/';
+
+
+$r = new TestRegexIterator(new myIterator, $rege);
+
+
+try{
+ $r->setPregFlags();
+}catch (Exception $e) {
+ echo $e->getMessage();
+}
+
+?>
+--EXPECTF--
+Warning: RegexIterator::setPregFlags() expects exactly 1 parameter, 0 given in %s
\ No newline at end of file diff --git a/ext/spl/tests/spl_autoload_bug48541.phpt b/ext/spl/tests/spl_autoload_bug48541.phpt new file mode 100644 index 000000000..eef81bd03 --- /dev/null +++ b/ext/spl/tests/spl_autoload_bug48541.phpt @@ -0,0 +1,24 @@ +--TEST-- +SPL: spl_autoload_register() Bug #48541: registering multiple closures fails with memleaks +--FILE-- +<?php +$a = function ($class) { + echo "a called\n"; +}; +$b = function ($class) { + eval('class ' . $class . '{function __construct(){echo "foo\n";}}'); + echo "b called\n"; +}; +spl_autoload_register($a); +spl_autoload_register($b); + +$c = $a; +spl_autoload_register($c); +$c = new foo; +?> +===DONE=== +--EXPECT-- +a called +b called +foo +===DONE===
\ No newline at end of file diff --git a/ext/spl/tests/spl_caching_iterator_constructor_flags.phpt b/ext/spl/tests/spl_caching_iterator_constructor_flags.phpt new file mode 100644 index 000000000..499cd6755 --- /dev/null +++ b/ext/spl/tests/spl_caching_iterator_constructor_flags.phpt @@ -0,0 +1,25 @@ +--TEST-- +SPL: CachingInterator constructor flag checks +--CREDITS-- +Sean Burlington www.practicalweb.co.uk +TestFest London May 2009 +--FILE-- +<?php + //line 681 ... + $array = array(array(7,8,9),1,2,3,array(4,5,6)); +$arrayIterator = new ArrayIterator($array); +try { +$test = new CachingIterator($arrayIterator, 0); +$test = new CachingIterator($arrayIterator, 1); +$test = new CachingIterator($arrayIterator, 2); +$test = new CachingIterator($arrayIterator, 3); // this throws an exception +} catch (InvalidArgumentException $e){ + print $e->getMessage() . "\n"; +} + + +?> +===DONE=== +--EXPECTF-- +Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_CURRENT +===DONE=== diff --git a/ext/spl/tests/spl_cachingiterator___toString_basic.phpt b/ext/spl/tests/spl_cachingiterator___toString_basic.phpt new file mode 100644 index 000000000..0395b3794 --- /dev/null +++ b/ext/spl/tests/spl_cachingiterator___toString_basic.phpt @@ -0,0 +1,16 @@ +--TEST-- +SPL: SplCachingIterator, Test method to convert current element to string +--CREDITS-- +Chris Scott chris.scott@nstein.com +#testfest London 2009-05-09 +--FILE-- +<?php + +$ai = new ArrayIterator(array(new stdClass(), new stdClass())); +$ci = new CachingIterator($ai); +var_dump( +$ci->__toString() // if conversion to string is done by echo, for example, an exeption is thrown. Invoking __toString explicitly covers different code. +); +?> +--EXPECTF-- +NULL diff --git a/ext/spl/tests/spl_cachingiterator_setFlags_basic.phpt b/ext/spl/tests/spl_cachingiterator_setFlags_basic.phpt new file mode 100644 index 000000000..126586bcc --- /dev/null +++ b/ext/spl/tests/spl_cachingiterator_setFlags_basic.phpt @@ -0,0 +1,16 @@ +--TEST-- +SPL: SplCachingIterator, Test method to set flags for caching iterator +--CREDITS-- +Chris Scott chris.scott@nstein.com +#testfest London 2009-05-09 +--FILE-- +<?php + +$ai = new ArrayIterator(array('foo', 'bar')); + +$ci = new CachingIterator($ai); +$ci->setFlags(); //expects arg + +?> +--EXPECTF-- +Warning: CachingIterator::setFlags() expects exactly 1 parameter, %s diff --git a/ext/spl/tests/spl_classes.phpt b/ext/spl/tests/spl_classes.phpt new file mode 100644 index 000000000..172c4ab92 --- /dev/null +++ b/ext/spl/tests/spl_classes.phpt @@ -0,0 +1,13 @@ +--TEST-- +SPL: spl_classes() function +--CREDITS-- +Sebastian Schürmann +sebs@php.net +Testfest 2009 Munich +--FILE-- +<?php +var_dump(is_array(spl_classes())); +?> +--EXPECT-- +bool(true) + diff --git a/ext/spl/tests/spl_fileinfo_getlinktarget_basic.phpt b/ext/spl/tests/spl_fileinfo_getlinktarget_basic.phpt new file mode 100755 index 000000000..9e3debfa9 --- /dev/null +++ b/ext/spl/tests/spl_fileinfo_getlinktarget_basic.phpt @@ -0,0 +1,22 @@ +--TEST--
+SPL: Spl File Info test getLinkTarget
+--CREDITS--
+Nataniel McHugh nat@fishtrap.co.uk
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN') die("skip this test not for Windows platforms");
+?>
+--FILE--
+<?php
+$link = 'test_link';
+symlink(__FILE__, $link );
+$fileInfo = new SplFileInfo($link);
+
+if ($fileInfo->isLink()) {
+ echo $fileInfo->getLinkTarget() == __FILE__ ? 'same' : 'different',PHP_EOL;
+}
+var_dump(unlink($link));
+?>
+--EXPECT--
+same
+bool(true)
diff --git a/ext/spl/tests/spl_heap_count_basic.phpt b/ext/spl/tests/spl_heap_count_basic.phpt new file mode 100644 index 000000000..6e6baf6c9 --- /dev/null +++ b/ext/spl/tests/spl_heap_count_basic.phpt @@ -0,0 +1,35 @@ +--TEST-- +SPL: SplHeap, Test spl_heap_object_count_elements (spl_heap.c:490) for returning count() failure for Heaps +--CREDITS-- +Chris Scott chris.scott@nstein.com +#testfest London 2009-05-09 +--FILE-- +<?php + +class MyHeap extends SplHeap +{ + public function compare($a,$b) + { + return ($a < $b); + } + + public function count() // override count to force failure + { + throw new Exception('Cause count to fail'); + return parent::count(); + } +} + + +$heap = new MyHeap(); +$heap->insert(1); +count($heap);// refers to MyHeap->count() method + +?> +--EXPECTF-- +Fatal error: Uncaught exception 'Exception' with message 'Cause count to fail' in %s +Stack trace: +#0 [internal function]: MyHeap->count() +#1 %s count(Object(MyHeap)) +#2 {main} + thrown in %s on line %d diff --git a/ext/spl/tests/spl_heap_count_error.phpt b/ext/spl/tests/spl_heap_count_error.phpt new file mode 100644 index 000000000..6bed4cfa6 --- /dev/null +++ b/ext/spl/tests/spl_heap_count_error.phpt @@ -0,0 +1,12 @@ +--TEST-- +SPL: Priority queue count, illegal number of args +--CREDITS-- +Mark Schaschke (mark@fractalturtle.com) +TestFest London May 2009 +--FILE-- +<?php +$h = new SplPriorityQueue(); +$h->count(1); +?> +--EXPECTF-- +Warning: SplPriorityQueue::count() expects exactly 0 parameters, 1 given in %s diff --git a/ext/spl/tests/spl_heap_extract_parameter_error.phpt b/ext/spl/tests/spl_heap_extract_parameter_error.phpt new file mode 100644 index 000000000..aecd03dfa --- /dev/null +++ b/ext/spl/tests/spl_heap_extract_parameter_error.phpt @@ -0,0 +1,27 @@ +--TEST-- +SPL: Heap and extract with parameter +--CREDITS-- +Sean Burlington www.practicalweb.co.uk +TestFest London May 2009 +--FILE-- +<?php + +class TestHeap extends SplHeap { + + function compare() { + print "This shouldn't be printed"; + } +} + +$testHeap = new TestHeap(); + + + +var_dump($testHeap->extract('test')); + +?> +===DONE=== +--EXPECTF-- +Warning: SplHeap::extract() expects exactly 0 parameters, 1 given in %s on line 14 +NULL +===DONE=== diff --git a/ext/spl/tests/spl_heap_insert_basic.phpt b/ext/spl/tests/spl_heap_insert_basic.phpt new file mode 100644 index 000000000..76a34b292 --- /dev/null +++ b/ext/spl/tests/spl_heap_insert_basic.phpt @@ -0,0 +1,20 @@ +--TEST-- +SPL: SplHeap, Test method to insert into heap +--CREDITS-- +Chris Scott chris.scott@nstein.com +#testfest London 2009-05-09 +--FILE-- +<?php +class MyHeap extends SplHeap +{ + public function compare($a, $b) + { + return $a < $b; + } +} + +$heap = new MyHeap(); +$heap->insert(1,2); +?> +--EXPECTF-- +Warning: SplHeap::insert() expects exactly 1 parameter, %s diff --git a/ext/spl/tests/spl_heap_is_empty_basic.phpt b/ext/spl/tests/spl_heap_is_empty_basic.phpt new file mode 100644 index 000000000..7c2937918 --- /dev/null +++ b/ext/spl/tests/spl_heap_is_empty_basic.phpt @@ -0,0 +1,31 @@ +--TEST--
+SPL: SplHeap, test trivial method to find if a heap is empty
+--CREDITS--
+Nathaniel McHugh nat@fishtrap.co.uk
+#testfest London 2009-05-09
+--FILE--
+<?php
+
+class MyHeap extends SplHeap{
+
+public function compare($a, $b){
+return $a < $b;
+}
+
+}
+
+
+$heap = new MyHeap();
+var_dump($heap->isEmpty());
+$heap->insert(1);
+var_dump($heap->isEmpty());
+$heap->extract();
+var_dump($heap->isEmpty());
+$heap->isEmpty('var');
+?>
+--EXPECTF--
+bool(true)
+bool(false)
+bool(true)
+
+Warning: SplHeap::isEmpty() expects exactly 0 parameters, 1 given in %s
diff --git a/ext/spl/tests/spl_heap_isempty.phpt b/ext/spl/tests/spl_heap_isempty.phpt new file mode 100644 index 000000000..5d3e4cafc --- /dev/null +++ b/ext/spl/tests/spl_heap_isempty.phpt @@ -0,0 +1,21 @@ +--TEST--
+SPL: Test of isEmpty for SPL Max Heap
+--CREDITS--
+Rohan Abraham (rohanabrahams@gmail.com)
+TestFest London May 2009
+--FILE--
+<?php
+ $h = new SplMaxHeap();
+ echo "Checking a new heap is empty: ";
+ var_dump($h->isEmpty())."\n";
+ $h->insert(2);
+ echo "Checking after insert: ";
+ var_dump($h->isEmpty())."\n";
+ $h->extract();
+ echo "Checking after extract: ";
+ var_dump($h->isEmpty())."\n";
+?>
+--EXPECT--
+Checking a new heap is empty: bool(true)
+Checking after insert: bool(false)
+Checking after extract: bool(true)
\ No newline at end of file diff --git a/ext/spl/tests/spl_heap_iteration_error.phpt b/ext/spl/tests/spl_heap_iteration_error.phpt new file mode 100644 index 000000000..62e462f55 --- /dev/null +++ b/ext/spl/tests/spl_heap_iteration_error.phpt @@ -0,0 +1,53 @@ +--TEST-- +SPL: Attempt to corrupt the heap while iterating +--CREDITS-- +Lukasz Andrzejak meltir@meltir.com +#testfest London 2009-05-09 +--FILE-- +<?php +class ext_heap extends SplMaxHeap { + public $fail = false; + public function compare($val1,$val2) { + if ($this->fail) + throw new Exception('Corrupting heap',99); + return 0; + } +} + +$h = new ext_heap(); +$h->insert(array('foobar')); +$h->insert(array('foobar1')); +$h->insert(array('foobar2')); + +try { + $h->fail=true; + foreach ($h as $value) {}; + echo "I should have raised an exception here"; +} catch (Exception $e) { + if ($e->getCode()!=99) echo "Unexpected exception"; +} + +var_dump($h); +?> +--EXPECTF-- +object(ext_heap)#%d (4) { + [%u|b%"fail"]=> + bool(true) + [%u|b%"flags":%u|b%"SplHeap":private]=> + int(0) + [%u|b%"isCorrupted":%u|b%"SplHeap":private]=> + bool(true) + [%u|b%"heap":%u|b%"SplHeap":private]=> + array(2) { + [0]=> + array(1) { + [0]=> + %unicode|string%(7) "foobar2" + } + [1]=> + array(1) { + [0]=> + %unicode|string%(7) "foobar1" + } + } +} diff --git a/ext/spl/tests/spl_heap_recoverfromcorruption_arguments.phpt b/ext/spl/tests/spl_heap_recoverfromcorruption_arguments.phpt new file mode 100644 index 000000000..8726f4b32 --- /dev/null +++ b/ext/spl/tests/spl_heap_recoverfromcorruption_arguments.phpt @@ -0,0 +1,15 @@ +--TEST-- +SPL: SplHeap check no arguments to be accepted on recoverFromCorruption +--CREDITS-- +Rohan Abraham (rohanabrahams@gmail.com) +TestFest London May 2009 +--FILE-- +<?php + $h = new SplMaxHeap(); + //Line below should throw a warning as no args are expected + $h->recoverFromCorruption("no args"); +?> +--EXPECTF-- + +Warning: SplHeap::recoverFromCorruption() expects exactly 0 parameters, 1 given in %s on line %d + diff --git a/ext/spl/tests/spl_iterator_apply_error.phpt b/ext/spl/tests/spl_iterator_apply_error.phpt new file mode 100755 index 000000000..8e7cba483 --- /dev/null +++ b/ext/spl/tests/spl_iterator_apply_error.phpt @@ -0,0 +1,26 @@ +--TEST-- +SPL: Error: iterator_apply when an iterator method (eg rewind) throws exception +--FILE-- +<?php + +class MyArrayIterator extends ArrayIterator { + public function rewind() { + throw new Exception('Make the iterator break'); + } +} + +function test() {} + +$it = new MyArrayIterator(array(1, 21, 22)); + +try { + $res = iterator_apply($it, 'test'); +} catch (Exception $e) { + echo $e->getMessage(); +} + +?> + +<?php exit(0); ?> +--EXPECT-- +Make the iterator break diff --git a/ext/spl/tests/spl_iterator_apply_error_001.phpt b/ext/spl/tests/spl_iterator_apply_error_001.phpt new file mode 100755 index 000000000..54663c0da --- /dev/null +++ b/ext/spl/tests/spl_iterator_apply_error_001.phpt @@ -0,0 +1,20 @@ +--TEST-- +SPL: Error: iterator_apply when the callback throws an exception +--FILE-- +<?php + +function test() { + throw new Exception('Broken callback'); +} + +$it = new RecursiveArrayIterator(array(1, 21, 22)); + +try { + iterator_apply($it, 'test'); +} catch (Exception $e) { + echo $e->getMessage(); +} + +?> +--EXPECT-- +Broken callback diff --git a/ext/spl/tests/spl_iterator_caching_count_basic.phpt b/ext/spl/tests/spl_iterator_caching_count_basic.phpt new file mode 100644 index 000000000..b11eb7b54 --- /dev/null +++ b/ext/spl/tests/spl_iterator_caching_count_basic.phpt @@ -0,0 +1,21 @@ +--TEST-- +SPL: Caching iterator count() cache contents +--CREDITS-- +Lukasz Andrzejak meltir@meltir.com +#testfest London 2009-05-09 +--FILE-- +<?php +$i = new ArrayIterator(array(1,1,1,1,1)); +$i = new CachingIterator($i,CachingIterator::FULL_CACHE); +foreach ($i as $value) { + echo $i->count()."\n"; +} +?> +===DONE=== +--EXPECT-- +1 +2 +3 +4 +5 +===DONE===
\ No newline at end of file diff --git a/ext/spl/tests/spl_iterator_caching_count_error.phpt b/ext/spl/tests/spl_iterator_caching_count_error.phpt new file mode 100644 index 000000000..70aa2be30 --- /dev/null +++ b/ext/spl/tests/spl_iterator_caching_count_error.phpt @@ -0,0 +1,21 @@ +--TEST-- +SPL: Caching iterator count() cache failure +--CREDITS-- +Lukasz Andrzejak meltir@meltir.com +#testfest London 2009-05-09 +--FILE-- +<?php +$i = new ArrayIterator(array(1,1,1,1,1)); +$i = new CachingIterator($i); +try { + $i->count(); + echo "Should have caused an exception"; +} catch (BadMethodCallException $e) { + echo "Exception raised\n"; +} + +?> +===DONE=== +--EXPECT-- +Exception raised +===DONE===
\ No newline at end of file diff --git a/ext/spl/tests/spl_iterator_caching_getcache_error.phpt b/ext/spl/tests/spl_iterator_caching_getcache_error.phpt new file mode 100644 index 000000000..2ea4bd819 --- /dev/null +++ b/ext/spl/tests/spl_iterator_caching_getcache_error.phpt @@ -0,0 +1,21 @@ +--TEST-- +SPL: Caching iterator getCache failure +--CREDITS-- +Lukasz Andrzejak meltir@meltir.com +#testfest London 2009-05-09 +--FILE-- +<?php +$i = new ArrayIterator(array(1,1,1,1,1)); +$i = new CachingIterator($i); +try { + $i->getCache(); + echo "Should have caused an exception"; +} catch (BadMethodCallException $e) { + echo "Exception raised\n"; +} + +?> +===DONE=== +--EXPECT-- +Exception raised +===DONE===
\ No newline at end of file diff --git a/ext/spl/tests/spl_iterator_getcallchildren.phpt b/ext/spl/tests/spl_iterator_getcallchildren.phpt new file mode 100644 index 000000000..77b03b6b7 --- /dev/null +++ b/ext/spl/tests/spl_iterator_getcallchildren.phpt @@ -0,0 +1,39 @@ +--TEST-- +SPL: RecursiveIteratorIterator, getCallChildren +--CREDITS-- +Sean Burlington www.practicalweb.co.uk +TestFest London May 2009 +--FILE-- +<?php + //line 681 ... + $array = array(array(7,8,9),1,2,3,array(4,5,6)); +$recursiveArrayIterator = new RecursiveArrayIterator($array); +$test = new RecursiveIteratorIterator($recursiveArrayIterator); + +var_dump($test->current()); +$test->next(); +var_dump($test->current()); +try { + $output = $test->callGetChildren(); +} catch (InvalidArgumentException $ilae){ + $output = null; + print "invalid argument exception\n"; +} +var_dump($output); + + +?> +===DONE=== +--EXPECTF-- + array(3) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) +} +int(7) +invalid argument exception +NULL +===DONE=== diff --git a/ext/spl/tests/spl_iterator_iterator_constructor.phpt b/ext/spl/tests/spl_iterator_iterator_constructor.phpt new file mode 100644 index 000000000..d4fdb14c1 --- /dev/null +++ b/ext/spl/tests/spl_iterator_iterator_constructor.phpt @@ -0,0 +1,30 @@ +--TEST-- +SPL: IteratorInterator constructor checks +--CREDITS-- +Sean Burlington www.practicalweb.co.uk +TestFest London May 2009 +--FILE-- +<?php + + //I think this is testing line 1297 of spl_iterators.c + + $array = array(array(7,8,9),1,2,3,array(4,5,6)); +$arrayIterator = new ArrayIterator($array); +try { +$test = new IteratorIterator($arrayIterator); + +$test = new IteratorIterator($arrayIterator, 1); +$test = new IteratorIterator($arrayIterator, 1, 1); +$test = new IteratorIterator($arrayIterator, 1, 1, 1); +$test = new IteratorIterator($arrayIterator, 1, 1, 1, 1); + +} catch (InvalidArgumentException $e){ + print $e->getMessage() . "\n"; +} + + +?> +===DONE=== +--EXPECTF-- +IteratorIterator::__construct() expects at most 2 parameters, 3 given +===DONE=== diff --git a/ext/spl/tests/spl_iterator_recursive_getiterator_error.phpt b/ext/spl/tests/spl_iterator_recursive_getiterator_error.phpt new file mode 100644 index 000000000..0d45c3151 --- /dev/null +++ b/ext/spl/tests/spl_iterator_recursive_getiterator_error.phpt @@ -0,0 +1,16 @@ +--TEST-- +SPL: IteratorIterator foreach by reference failure +--CREDITS-- +Lukasz Andrzejak meltir@meltir.com +#testfest London 2009-05-09 +--FILE-- +<?php +$i = new ArrayIterator(array(1,1,1,1,1)); +$iii = new IteratorIterator($i); +p($iii); +function p ($i) { + foreach ($i as &$value) {} +} +?> +--EXPECTF-- +Fatal error: An iterator cannot be used with foreach by reference in %s
\ No newline at end of file diff --git a/ext/spl/tests/spl_iterator_to_array_basic.phpt b/ext/spl/tests/spl_iterator_to_array_basic.phpt new file mode 100644 index 000000000..68cb8792a --- /dev/null +++ b/ext/spl/tests/spl_iterator_to_array_basic.phpt @@ -0,0 +1,13 @@ +--TEST-- +SPL: iterator_to_array, Test function to convert iterator to array +--CREDITS-- +Chris Scott chris.scott@nstein.com +#testfest London 2009-05-09 +--FILE-- +<?php + +iterator_to_array();//requires iterator as arg + +?> +--EXPECTF-- +Warning: iterator_to_array() expects at least 1 parameter, %s diff --git a/ext/spl/tests/spl_iterator_to_array_error.phpt b/ext/spl/tests/spl_iterator_to_array_error.phpt new file mode 100755 index 000000000..755ef7b99 --- /dev/null +++ b/ext/spl/tests/spl_iterator_to_array_error.phpt @@ -0,0 +1,33 @@ +--TEST-- +SPL: Error: iterator_to_array when the current operation throws an exception +--FILE-- +<?php + +class MyArrayIterator extends ArrayIterator { + public function current() { + throw new Exception('Make the iterator break'); + } +} + +$it = new MyArrayIterator(array(4, 6, 2)); + +try { + // get keys + $ar = iterator_to_array($it); +} catch (Exception $e) { + echo $e->getMessage() . PHP_EOL; +} + +try { + // get values + $ar = iterator_to_array($it, false); +} catch (Exception $e) { + echo $e->getMessage() . PHP_EOL; +} + +?> + +<?php exit(0); ?> +--EXPECT-- +Make the iterator break +Make the iterator break diff --git a/ext/spl/tests/spl_limit_iterator_check_limits.phpt b/ext/spl/tests/spl_limit_iterator_check_limits.phpt new file mode 100644 index 000000000..01436a8fb --- /dev/null +++ b/ext/spl/tests/spl_limit_iterator_check_limits.phpt @@ -0,0 +1,37 @@ +--TEST-- +SPL: LimitIterator check limits are valid +--CREDITS-- +Sean Burlington www.practicalweb.co.uk +TestFest London May 2009 +--FILE-- +<?php + $array = array(array(7,8,9),1,2,3,array(4,5,6)); +$arrayIterator = new ArrayIterator($array); + +try { + $limitIterator = new LimitIterator($arrayIterator, -1); +} catch (OutOfRangeException $e){ + print $e->getMessage(). "\n"; +} + + +try { + $limitIterator = new LimitIterator($arrayIterator, 0, -2); +} catch (OutOfRangeException $e){ + print $e->getMessage() . "\n"; +} + +try { + $limitIterator = new LimitIterator($arrayIterator, 0, -1); +} catch (OutOfRangeException $e){ + print $e->getMessage() . "\n"; +} + + + +?> +===DONE=== +--EXPECTF-- +Parameter offset must be > 0 +Parameter count must either be -1 or a value greater than or equal 0 +===DONE=== diff --git a/ext/spl/tests/spl_maxheap_compare_basic.phpt b/ext/spl/tests/spl_maxheap_compare_basic.phpt new file mode 100644 index 000000000..3705b3fd0 --- /dev/null +++ b/ext/spl/tests/spl_maxheap_compare_basic.phpt @@ -0,0 +1,22 @@ +--TEST-- +SPL: SplMaxHeap, Test method to comare elements +--CREDITS-- +Chris Scott chris.scott@nstein.com +#testfest London 2009-05-09 +--FILE-- +<?php + +class MyHeap extends SplMaxHeap +{ + public function testCompare() + { + return parent::compare(1); + } +} + +$heap = new MyHeap(); +$heap->testCompare(); + +?> +--EXPECTF-- +Warning: SplMaxHeap::compare() expects exactly 2 parameters, %s diff --git a/ext/spl/tests/spl_minheap_compare_error.phpt b/ext/spl/tests/spl_minheap_compare_error.phpt new file mode 100644 index 000000000..7120a6cd1 --- /dev/null +++ b/ext/spl/tests/spl_minheap_compare_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +SPL: SplMinHeap compare, illegal number of args +--CREDITS-- +Mark Schaschke (mark@fractalturtle.com) +TestFest London May 2009 +--FILE-- +<?php +class SplMinHeap2 extends SplMinHeap { + public function testCompare1() { + return parent::compare(); + } + public function testCompare2() { + return parent::compare(1); + } + public function testCompare3() { + return parent::compare(1, 2, 3); + } +} + +$h = new SplMinHeap2(); +$h->testCompare1(); +$h->testCompare2(); +$h->testCompare3(); +?> +--EXPECTF-- +Warning: SplMinHeap::compare() expects exactly 2 parameters, 0 given in %s + +Warning: SplMinHeap::compare() expects exactly 2 parameters, 1 given in %s + +Warning: SplMinHeap::compare() expects exactly 2 parameters, 3 given in %s + diff --git a/ext/spl/tests/spl_pq_top_basic.phpt b/ext/spl/tests/spl_pq_top_basic.phpt new file mode 100644 index 000000000..df85237a8 --- /dev/null +++ b/ext/spl/tests/spl_pq_top_basic.phpt @@ -0,0 +1,42 @@ +--TEST--
+SPL: SplPriorityQueue: top and extract flags
+--CREDITS--
+Nathaniel McHugh nat@fishtrap.co.uk
+#testfest London 2009-05-09
+--FILE--
+<?php
+
+$priorityQueue = new SplPriorityQueue();
+
+$priorityQueue->insert("a", 1);
+$priorityQueue->insert("b", 2);
+$priorityQueue->insert("c", 0);
+
+echo "EXTR DEFAULT",PHP_EOL;
+echo "value: ",$priorityQueue->top(),PHP_EOL;
+
+$priorityQueue->setExtractFlags(SplPriorityQueue::EXTR_PRIORITY);
+echo "EXTR_PRIORITY",PHP_EOL;
+echo "priority: ",$priorityQueue->top(),PHP_EOL;
+
+$priorityQueue->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
+echo "EXTR_BOTH",PHP_EOL;
+print_r($priorityQueue->top());
+
+echo "EXTR_DATA",PHP_EOL;
+$priorityQueue->setExtractFlags(SplPriorityQueue::EXTR_DATA);
+echo "value: ",$priorityQueue->top(),PHP_EOL;
+?>
+--EXPECT--
+EXTR DEFAULT
+value: b
+EXTR_PRIORITY
+priority: 2
+EXTR_BOTH
+Array
+(
+ [data] => b
+ [priority] => 2
+)
+EXTR_DATA
+value: b
\ No newline at end of file diff --git a/ext/spl/tests/spl_pq_top_error_args.phpt b/ext/spl/tests/spl_pq_top_error_args.phpt new file mode 100644 index 000000000..a0e596903 --- /dev/null +++ b/ext/spl/tests/spl_pq_top_error_args.phpt @@ -0,0 +1,12 @@ +--TEST-- +SPL: SplPriorityQueue: top too many arguments exception +--CREDITS-- +Nathaniel McHugh nat@fishtrap.co.uk +#testfest London 2009-05-09 +--FILE-- +<?php +$priorityQueue = new SplPriorityQueue(); +$priorityQueue->top('var'); +?> +--EXPECTF-- +Warning: SplPriorityQueue::top() expects exactly 0 parameters, 1 given in %s
\ No newline at end of file diff --git a/ext/spl/tests/spl_pq_top_error_corrupt.phpt b/ext/spl/tests/spl_pq_top_error_corrupt.phpt new file mode 100644 index 000000000..ea3e1fe50 --- /dev/null +++ b/ext/spl/tests/spl_pq_top_error_corrupt.phpt @@ -0,0 +1,37 @@ +--TEST--
+SPL: SplPriorityQueue: top and extract flags
+--CREDITS--
+Nathaniel McHugh nat@fishtrap.co.uk
+#testfest 2009-05-09
+--FILE--
+<?php + +class myPriorityQueue extends SplPriorityQueue{ + + public function compare($a, $b){ + if ($b == 2) { + throw new Exception('ignore me'); + } else { + return parent::compare($a, $b); + } + } +} + +$priorityQueue = new myPriorityQueue();
+$priorityQueue->insert("a", 1);
+try {
+ //corrupt heap
+ $priorityQueue->insert("b", 2); + // ignore exception tested elsewhere
+} catch (Exception $e) {
+}
+
+try {
+ $priorityQueue->top();
+} catch (RuntimeException $e) {
+ echo "Exception: ".$e->getMessage().PHP_EOL;
+}
+
+?>
+--EXPECT--
+Exception: Heap is corrupted, heap properties are no longer ensured. diff --git a/ext/spl/tests/spl_pq_top_error_empty.phpt b/ext/spl/tests/spl_pq_top_error_empty.phpt new file mode 100644 index 000000000..129a04891 --- /dev/null +++ b/ext/spl/tests/spl_pq_top_error_empty.phpt @@ -0,0 +1,19 @@ +--TEST--
+SPL: SplPriorityQueue: top exception on empty heap
+--CREDITS--
+Nathaniel McHugh nat@fishtrap.co.uk
+#testfest 2009-05-09
+--FILE--
+<?php +
+$priorityQueue = new SplPriorityQueue();
+
+try {
+ $priorityQueue->top();
+} catch (RuntimeException $e) {
+ echo "Exception: ".$e->getMessage().PHP_EOL;
+}
+
+?>
+--EXPECT--
+Exception: Can't peek at an empty heap diff --git a/ext/spl/tests/spl_priorityqeue_insert_two_params_error.phpt b/ext/spl/tests/spl_priorityqeue_insert_two_params_error.phpt new file mode 100644 index 000000000..659ffb4bc --- /dev/null +++ b/ext/spl/tests/spl_priorityqeue_insert_two_params_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +SPL: priorityQueue paramter test on insert method +--CREDITS-- +Sean Burlington www.practicalweb.co.uk +TestFest London May 2009 +--FILE-- +<?php + + +$testHeap = new SplPriorityQueue(); + + +var_dump($testHeap->insert()); +var_dump($testHeap->insert('test')); +var_dump($testHeap->insert('test', 'test')); +var_dump($testHeap->insert('test', 'test', 'test')); + + +?> +===DONE=== +--EXPECTF-- +Warning: SplPriorityQueue::insert() expects exactly 2 parameters, 0 given in %s on line 7 +NULL + +Warning: SplPriorityQueue::insert() expects exactly 2 parameters, 1 given in %s on line 8 +NULL +bool(true) + +Warning: SplPriorityQueue::insert() expects exactly 2 parameters, 3 given in %s on line 10 +NULL +===DONE=== diff --git a/ext/spl/tests/spl_recursiveIteratorIterator_setMaxDepth_parameter_count.phpt b/ext/spl/tests/spl_recursiveIteratorIterator_setMaxDepth_parameter_count.phpt new file mode 100644 index 000000000..d52a3208e --- /dev/null +++ b/ext/spl/tests/spl_recursiveIteratorIterator_setMaxDepth_parameter_count.phpt @@ -0,0 +1,28 @@ +--TEST-- +SPL: RecursiveIteratorIterator, setMaxDepth check parameter count +--CREDITS-- +Sean Burlington www.practicalweb.co.uk +TestFest London May 2009 +--FILE-- +<?php + //line 681 ... + $array = array(array(7,8,9),1,2,3,array(4,5,6)); +$recursiveArrayIterator = new RecursiveArrayIterator($array); +$test = new RecursiveIteratorIterator($recursiveArrayIterator); + +//var_dump($test->current()); +$test->setMaxDepth(); +$test->setMaxDepth(1); +$test->setMaxDepth(1,2); +$test->setMaxDepth(1,2,3); + +//var_dump($test->current()); + + +?> +===DONE=== +--EXPECTF-- +Warning: RecursiveIteratorIterator::setMaxDepth() expects at most 1 parameter, 2 given in %s on line 10 + +Warning: RecursiveIteratorIterator::setMaxDepth() expects at most 1 parameter, 3 given in %s on line 11 +===DONE=== diff --git a/ext/spl/tests/spl_recursive_iterator_iterator_key_case.phpt b/ext/spl/tests/spl_recursive_iterator_iterator_key_case.phpt new file mode 100644 index 000000000..249830859 --- /dev/null +++ b/ext/spl/tests/spl_recursive_iterator_iterator_key_case.phpt @@ -0,0 +1,33 @@ +--TEST--
+SPL: Test on RecursiveIteratorIterator key function checking switch statements
+--CREDITS--
+Rohan Abraham (rohanabrahams@gmail.com)
+TestFest London May 2009
+--FILE--
+<?php
+ $ar = array("one"=>1, "two"=>2, "three"=>array("four"=>4, "five"=>5, "six"=>array("seven"=>7)), "eight"=>8, -100 => 10, NULL => "null");
+ $it = new RecursiveArrayIterator($ar);
+ $it = new RecursiveIteratorIterator($it);
+ foreach($it as $k=>$v)
+ {
+ echo "$k=>$v\n";
+ var_dump($k);
+ }
+?>
+--EXPECTF--
+one=>1
+%unicode|string%(3) "one"
+two=>2
+%unicode|string%(3) "two"
+four=>4
+%unicode|string%(4) "four"
+five=>5
+%unicode|string%(4) "five"
+seven=>7
+%unicode|string%(5) "seven"
+eight=>8
+%unicode|string%(5) "eight"
+-100=>10
+int(-100)
+=>null
+%unicode|string%(0) ""
diff --git a/ext/spl/tests/splpriorityqueue_extract.phpt b/ext/spl/tests/splpriorityqueue_extract.phpt new file mode 100644 index 000000000..eee7bb2f7 --- /dev/null +++ b/ext/spl/tests/splpriorityqueue_extract.phpt @@ -0,0 +1,19 @@ +--TEST-- +SPL: splpriorityqueue extract() Test arguments +--CREDITS-- +Roshan Abraham (roshanabrahams@gmail.com) +TestFest London May 2009 +--FILE-- +<?php + +$sp = new SplPriorityQueue(); + +$sp->insert("1",1); + +$sp->extract(1); // Should throw a warning as extract expects NO arguments + +?> +--EXPECTF-- + +Warning: SplPriorityQueue::extract() expects exactly 0 parameters, 1 given in %s on line %d + diff --git a/ext/spl/tests/splpriorityqueue_setextractflags.phpt b/ext/spl/tests/splpriorityqueue_setextractflags.phpt new file mode 100644 index 000000000..97d86f375 --- /dev/null +++ b/ext/spl/tests/splpriorityqueue_setextractflags.phpt @@ -0,0 +1,17 @@ +--TEST-- +SPL: splpriorityqueue setExtractFlags() Test arguments +--CREDITS-- +Roshan Abraham (roshanabrahams@gmail.com) +TestFest London May 2009 +--FILE-- +<?php + +$sp = new SplPriorityQueue(); + +$sp->setExtractFlags(1,1); // Should throw a warning as setExtractFlags expects only 1 argument + +?> +--EXPECTF-- + +Warning: SplPriorityQueue::setExtractFlags() expects exactly 1 parameter, 2 given in %s on line %d + |
