Skip to content
Browse files

Added the initial version of the Github version.

  • Loading branch information...
0 parents commit 0546e5f2396db1a371b845cf1d5e93fec414a061 David Coallier committed May 10, 2011
2 CREDITS
@@ -0,0 +1,2 @@
+SPL_Types
+Marcus Boerger, David Coallier
11 config.m4
@@ -0,0 +1,11 @@
+dnl $Id: config.m4 250039 2008-01-06 20:40:26Z helly $
+dnl config.m4 for extension SPL Types
+
+PHP_ARG_ENABLE(spl-types, enable SPL Types suppport,
+[ --disable-spl-types Disable SPL Types], yes)
+
+if test "$PHP_SPL_TYPES" != "no"; then
+ AC_DEFINE(HAVE_SPL_TYPES, 1, [Whether you want SPL Types support])
+ PHP_NEW_EXTENSION(spl_types, php_spl_types.c spl_type.c, $ext_shared)
+ PHP_ADD_EXTENSION_DEP(spl_types, spl)
+fi
10 config.w32
@@ -0,0 +1,10 @@
+// $Id: config.w32 255800 2008-03-22 17:59:53Z sfox $
+// vim:ft=javascript
+
+ARG_ENABLE("spl_types", "SPL Types support", "no");
+
+if (PHP_SPL_TYPES != "no") {
+ EXTENSION("spl_types", "php_spl_types.c spl_type.c");
+ AC_DEFINE('HAVE_SPL_TYPES', 1);
+ ADD_EXTENSION_DEP('spl_types', 'spl')
+}
113 package.xml
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<package xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" packagerversion="1.4.7" version="2.0" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
+ <name>SPL_Types</name>
+ <channel>pecl.php.net</channel>
+ <summary>Standard PHP Library, Types Addon</summary>
+ <description>SPL Types is a collection of special typehandling classes.</description>
+ <lead>
+ <name>Marcus Boerger</name>
+ <user>helly</user>
+ <email>helly@php.net</email>
+ <active>yes</active>
+ </lead>
+ <lead>
+ <name>David Coallier</name>
+ <user>davidc</user>
+ <email>davidc@php.net</email>
+ <active>yes</active>
+ </lead>
+ <date>2011-01-18</date>
+ <version>
+ <release>0.3.1</release>
+ <api>1.0</api>
+ </version>
+ <stability>
+ <release>beta</release>
+ <api>beta</api>
+ </stability>
+ <license>PHP</license>
+ <notes>
+ - Support for 5.3.2
+ - Bug #17870: Fail to compile - spl_type.c:416: error: duplicate ‘static’
+ </notes>
+
+ <contents>
+ <dir name="/">
+ <file role="src" name="config.m4"/>
+ <file role="src" name="config.w32"/>
+ <file role="src" name="php_spl_types.c"/>
+ <file role="src" name="php_spl_types.h"/>
+ <file role="src" name="spl_type.c"/>
+ <file role="src" name="spl_type.h"/>
+ <file role="doc" name="CREDITS"/>
+ <dir name="tests">
+ <file role="test" name="001.phpt"/>
+ <file role="test" name="002.phpt"/>
+ <file role="test" name="003.phpt"/>
+ <file role="test" name="004.phpt"/>
+ <file role="test" name="005.phpt"/>
+ <file role="test" name="006.phpt"/>
+ </dir>
+ </dir>
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>5.1.0</min>
+ </php>
+ <pearinstaller>
+ <min>1.4.0</min>
+ </pearinstaller>
+ </required>
+ </dependencies>
+ <providesextension>SPL_Types</providesextension>
+ <extsrcrelease/>
+ <changelog>
+ <release>
+ <date>2008-01-13</date>
+ <version>
+ <release>0.3.0</release>
+ <api>1.0</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <license>PHP</license>
+ <notes>
+ - Support for 5.3
+ - Added new type (SplFloat)
+ - Support for OSX
+ </notes>
+ </release>
+ <release>
+ <version>
+ <release>0.2</release>
+ <api>1.0</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <date>2006-05-25</date>
+ <license>PHP</license>
+ <notes>- Initial version</notes>
+ </release>
+ <release>
+ <version>
+ <release>0.1</release>
+ <api>1.0</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <date>2006-05-25</date>
+ <license>PHP</license>
+ <notes>- Initial version</notes>
+ </release>
+ </changelog>
+</package>
+<!--
+vim:et:ts=1:sw=1
+-->
88 php_spl_types.c
@@ -0,0 +1,88 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2008 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Authors: Marcus Boerger <helly@php.net> |
+ +----------------------------------------------------------------------+
+ */
+
+/* $Id: php_spl_types.c 256509 2008-03-31 10:18:38Z sfox $ */
+
+#ifdef HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include "php.h"
+#include "php_ini.h"
+#include "ext/standard/info.h"
+#include "php_spl_types.h"
+#include "spl_type.h"
+
+#ifdef COMPILE_DL_SPL_TYPES
+ZEND_GET_MODULE(spl_types)
+#endif
+
+/* {{{ spl_functions_none
+ */
+zend_function_entry spl_types_functions[] = {
+ {NULL, NULL, NULL}
+};
+/* }}} */
+
+PHP_MINIT_FUNCTION(spl_types) /* {{{ */
+{
+ PHP_MINIT(spl_type)(INIT_FUNC_ARGS_PASSTHRU);
+
+ return SUCCESS;
+}
+/* }}} */
+
+static zend_module_dep spl_types_deps[] = {
+ ZEND_MOD_REQUIRED("spl")
+ {NULL, NULL, NULL}
+};
+
+zend_module_entry spl_types_module_entry = { /* {{{ */
+ STANDARD_MODULE_HEADER_EX, NULL,
+ spl_types_deps,
+ "SPL_Types",
+ spl_types_functions,
+ PHP_MINIT(spl_types),
+ NULL,
+ NULL,
+ NULL,
+ PHP_MINFO(spl_types),
+ PHP_SPL_TYPES_VERSION,
+ STANDARD_MODULE_PROPERTIES
+};
+/* }}} */
+
+/* {{{ PHP_MINFO(spl_types)
+ */
+PHP_MINFO_FUNCTION(spl_types)
+{
+ php_info_print_table_start();
+ php_info_print_table_header(2, "SPL Types support", "enabled");
+ php_info_print_table_row(2, "Version", PHP_SPL_TYPES_VERSION);
+ php_info_print_table_end();
+}
+/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: fdm=marker
+ * vim: noet sw=4 ts=4
+ */
58 php_spl_types.h
@@ -0,0 +1,58 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2008 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Authors: Marcus Boerger <helly@php.net> |
+ +----------------------------------------------------------------------+
+ */
+
+#ifndef PHP_SPL_TYPES_H
+#define PHP_SPL_TYPES_H
+
+#include "php.h"
+#include <stdarg.h>
+
+extern zend_module_entry spl_types_module_entry;
+#define phpext_spl_types_ptr &spl_types_module_entry
+
+#define PHP_SPL_TYPES_VERSION "0.4.0-dev"
+
+PHP_MINFO_FUNCTION(spl_types);
+
+#ifdef PHP_WIN32
+# ifdef SPL_TYPES_EXPORTS
+# define SPL_TYPES_API __declspec(dllexport)
+# elif defined(COMPILE_DL_SPL)
+# define SPL_TYPES_API __declspec(dllimport)
+# else
+# define SPL_TYPES_API /* nothing */
+# endif
+#else
+# define SPL_TYPES_API
+#endif
+
+#if defined(PHP_WIN32) && !defined(COMPILE_DL_SPL_TYPES)
+#undef phpext_spl_types
+#define phpext_spl_types NULL
+#endif
+
+#endif /* PHP_SPL_TYPES_H */
+
+/*
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim600: fdm=marker
+ * vim: noet sw=4 ts=4
+ */
502 spl_type.c
@@ -0,0 +1,502 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2008 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Authors: Marcus Boerger <helly@php.net> |
+ +----------------------------------------------------------------------+
+ */
+
+/* $Id: spl_type.c 279980 2009-05-05 15:25:56Z davidc $ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "php.h"
+#include "php_ini.h"
+#include "ext/standard/info.h"
+#include "zend_interfaces.h"
+#include "zend_exceptions.h"
+
+#include "php_spl_types.h"
+#include "ext/spl/spl_functions.h"
+#include "ext/spl/spl_engine.h"
+#include "ext/spl/spl_iterators.h"
+#include "ext/spl/spl_exceptions.h"
+#include "spl_type.h"
+
+#ifndef Z_ADDREF_P
+#define Z_ADDREF_P(x) (x)->refcount++
+#endif
+
+#ifndef Z_SET_REFCOUNT_P
+#define Z_SET_REFCOUNT_P(x, n) (x)->refcount = n
+#endif
+
+#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 2) || PHP_MAJOR_VERSION > 5
+# define SPL_TYPES_CALLABLE TSRMLS_CC
+#else
+# define SPL_TYPES_CALLABLE
+#endif
+
+zend_object_handlers spl_handler_SplType;
+SPL_TYPES_API zend_class_entry *spl_ce_SplType;
+SPL_TYPES_API zend_class_entry *spl_ce_SplEnum;
+SPL_TYPES_API zend_class_entry *spl_ce_SplBool;
+SPL_TYPES_API zend_class_entry *spl_ce_SplInt;
+SPL_TYPES_API zend_class_entry *spl_ce_SplFloat;
+SPL_TYPES_API zend_class_entry *spl_ce_SplString;
+
+static void spl_type_object_free_storage(void *_object TSRMLS_DC) /* {{{ */
+{
+ spl_type_object *object = (spl_type_object*)_object;
+
+ zend_hash_destroy(object->std.properties);
+ FREE_HASHTABLE(object->std.properties);
+
+ if (object->properties_copy) {
+ zend_hash_destroy(object->properties_copy);
+ FREE_HASHTABLE(object->properties_copy);
+ }
+
+ zval_ptr_dtor(&object->value);
+
+ efree(object);
+}
+/* }}} */
+
+static zend_object_value spl_type_object_new_ex(zend_class_entry *class_type, zend_bool spl_type_strict, spl_type_object **obj, spl_type_set_t set TSRMLS_DC) /* {{{ */
+{
+ zend_object_value retval;
+ spl_type_object *object;
+ zval *tmp, **def;
+
+ object = emalloc(sizeof(spl_type_object));
+ memset(object, 0, sizeof(spl_type_object));
+ object->std.ce = class_type;
+ object->set = set;
+ object->strict = spl_type_strict;
+ if (obj) *obj = object;
+
+ ALLOC_HASHTABLE(object->std.properties);
+ zend_hash_init(object->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
+ zend_hash_copy(object->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
+
+ retval.handle = zend_objects_store_put(object, (zend_objects_store_dtor_t) zend_objects_destroy_object, (zend_objects_free_object_storage_t) spl_type_object_free_storage, NULL TSRMLS_CC);
+ retval.handlers = &spl_handler_SplType;
+
+ zend_update_class_constants(class_type TSRMLS_CC);
+
+ ALLOC_INIT_ZVAL(object->value);
+
+ if (zend_hash_find(&class_type->constants_table, "__default", sizeof("__default"), (void **) &def) == FAILURE) {
+#if PHP_MAJOR_VERSION < 6
+ php_error_docref(NULL TSRMLS_CC, E_COMPILE_ERROR, "Class constant %s::__default doesn not exist", class_type->name);
+#else
+ php_error_docref(NULL TSRMLS_CC, E_COMPILE_ERROR, "Class constant %v::__default doesn not exist", class_type->name);
+#endif
+ return retval;
+ }
+
+ ZVAL_ZVAL(object->value, *def, 1, 0);
+
+ return retval;
+}
+/* }}} */
+
+static zend_object_value spl_type_object_clone(zval *zobject TSRMLS_DC) /* {{{ */
+{
+ zend_object_value new_obj_val;
+ zend_object *old_object;
+ zend_object *new_object;
+ zend_object_handle handle = Z_OBJ_HANDLE_P(zobject);
+ spl_type_object *object;
+ spl_type_object *source;
+
+ old_object = zend_objects_get_address(zobject TSRMLS_CC);
+ source = (spl_type_object*)old_object;
+
+ new_obj_val = spl_type_object_new_ex(old_object->ce, source->strict, &object, source->set TSRMLS_CC);
+ new_object = &object->std;
+
+ zend_objects_clone_members(new_object, new_obj_val, old_object, handle TSRMLS_CC);
+
+ ZVAL_ZVAL(object->value, source->value, 1, 0);
+
+ return new_obj_val;
+}
+/* }}} */
+
+static int spl_enum_apply_set(zval **pzconst, spl_type_set_info *inf TSRMLS_DC) /* {{{ */
+{
+ zval result;
+
+ INIT_ZVAL(result);
+
+ if (inf->done || is_equal_function(&result, *pzconst, inf->value TSRMLS_CC) == FAILURE)
+ {
+ return 0; /*ZEND_HASH_APPLY_KEEP;*/
+ }
+ if (Z_LVAL(result)) {
+ zval_dtor(inf->object->value);
+ ZVAL_ZVAL(inf->object->value, *pzconst, 1, 0);
+ inf->done = 1;
+ return 0; /*ZEND_HASH_APPLY_STOP;*/
+ }
+
+ return 0;/*ZEND_HASH_APPLY_KEEP;*/
+}
+/* }}} */
+
+static int spl_enum_apply_set_strict(zval **pzconst, spl_type_set_info *inf TSRMLS_DC) /* {{{ */
+{
+ zval result;
+
+ INIT_ZVAL(result);
+
+ if (inf->done || is_identical_function(&result, *pzconst, inf->value TSRMLS_CC) == FAILURE)
+ {
+ return 0; /*ZEND_HASH_APPLY_KEEP;*/
+ }
+ if (Z_LVAL(result)) {
+ zval_dtor(inf->object->value);
+ ZVAL_ZVAL(inf->object->value, *pzconst, 1, 0);
+ inf->done = 1;
+ return 0; /*ZEND_HASH_APPLY_STOP;*/
+ }
+
+ return 0;/*ZEND_HASH_APPLY_KEEP;*/
+}
+/* }}} */
+
+static void spl_type_set_enum(spl_type_set_info *inf TSRMLS_DC) /* {{{ */
+{
+ if (inf->object->strict) {
+ zend_hash_apply_with_argument(&inf->object->std.ce->constants_table, (apply_func_arg_t)spl_enum_apply_set_strict, (void*)inf TSRMLS_CC);
+ } else {
+ zend_hash_apply_with_argument(&inf->object->std.ce->constants_table, (apply_func_arg_t)spl_enum_apply_set, (void*)inf TSRMLS_CC);
+ }
+
+ if (!inf->done) {
+#if PHP_MAJOR_VERSION < 6
+ zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Value not a const in enum %s", inf->object->std.ce->name);
+#else
+ zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Value not a const in enum %v", inf->object->std.ce->name);
+#endif
+ }
+}
+/* }}} */
+
+static void spl_type_set_int(spl_type_set_info *inf TSRMLS_DC) /* {{{ */
+{
+ if (inf->object->strict && Z_TYPE_P(inf->value) != IS_LONG) {
+ zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Value not an integer");
+ } else {
+ zval_dtor(inf->object->value);
+ ZVAL_ZVAL(inf->object->value, inf->value, 1, 0);
+ convert_to_long_ex(&inf->object->value);
+ inf->done = 1;
+ }
+}
+/* }}} */
+
+static void spl_type_set_string(spl_type_set_info *inf TSRMLS_DC) /* {{{ */
+{
+ if (inf->object->strict && (Z_TYPE_P(inf->value) != IS_STRING)) {
+ zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Value not a string");
+ } else {
+ zval_dtor(inf->object->value);
+ ZVAL_ZVAL(inf->object->value, inf->value, 1, 0);
+ convert_to_string_ex(&inf->object->value);
+ inf->done = 1;
+ }
+}
+/* }}} */
+
+static void spl_type_set_float(spl_type_set_info *inf TSRMLS_DC) /* {{{ */
+{
+ if (inf->object->strict && (Z_TYPE_P(inf->value) != IS_DOUBLE && Z_TYPE_P(inf->value) != IS_LONG)) {
+ zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Value not a float");
+ } else {
+ zval_dtor(inf->object->value);
+ ZVAL_ZVAL(inf->object->value, inf->value, 1, 0);
+ convert_to_double_ex(&inf->object->value);
+ inf->done = 1;
+ }
+}
+/* }}} */
+
+static void spl_type_object_set(zval **pzobject, zval *value TSRMLS_DC) /* {{{ */
+{
+ spl_type_set_info inf;
+
+ inf.object = (spl_type_object*)zend_object_store_get_object(*pzobject TSRMLS_CC);
+ inf.value = value;
+ inf.done = 0;
+
+ if (!inf.object->std.ce) {
+#if PHP_MAJOR_VERSION < 6
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Value of type %s was not initialized properly", Z_OBJCE_PP(pzobject)->name);
+#else
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Value of type %v was not initialized properly", Z_OBJCE_PP(pzobject)->name);
+#endif
+ return;
+ }
+
+ if (Z_TYPE_P(value) == IS_OBJECT && Z_OBJ_HANDLER_P(value, get)) {
+ inf.value = Z_OBJ_HANDLER_P(value, get)(value TSRMLS_CC);
+ }
+
+ inf.object->set(&inf TSRMLS_CC);
+}
+/* }}} */
+
+static zval* spl_type_object_get(zval *zobject TSRMLS_DC) /* {{{ */
+{
+ spl_type_object *object = (spl_type_object*)zend_object_store_get_object(zobject TSRMLS_CC);
+ zval *value;
+
+ MAKE_STD_ZVAL(value);
+ ZVAL_ZVAL(value, object->value, 1, 0);
+ Z_SET_REFCOUNT_P(value, 0);
+
+ return value;
+} /* }}} */
+
+static HashTable* spl_type_object_get_properties(zval *zobject TSRMLS_DC) /* {{{ */
+{
+ spl_type_object *object = (spl_type_object*)zend_object_store_get_object(zobject TSRMLS_CC);
+ zval *tmp;
+
+ if (object->properties_copy) {
+ zend_hash_clean(object->properties_copy);
+ } else {
+ ALLOC_HASHTABLE(object->properties_copy);
+ zend_hash_init(object->properties_copy, 0, NULL, ZVAL_PTR_DTOR, 0);
+ }
+ zend_hash_copy(object->properties_copy, object->std.properties, (copy_ctor_func_t) zval_add_ref, (void*)&tmp, sizeof(zval *));
+
+ Z_ADDREF_P(object->value);
+ zend_hash_update(object->properties_copy, "__default", sizeof("__default"), (void*)&object->value, sizeof(zval *), (void**)&tmp);
+
+ return object->properties_copy;
+}
+/* }}} */
+
+#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 2)
+#define convert_to_explicit_type(pzv, type) \
+ do { \
+ switch (type) { \
+ case IS_NULL: \
+ convert_to_null(pzv); \
+ break; \
+ case IS_LONG: \
+ convert_to_long(pzv); \
+ break; \
+ case IS_DOUBLE: \
+ convert_to_double(pzv); \
+ break; \
+ case IS_BOOL: \
+ convert_to_boolean(pzv); \
+ break; \
+ case IS_ARRAY: \
+ convert_to_array(pzv); \
+ break; \
+ case IS_OBJECT: \
+ convert_to_object(pzv); \
+ break; \
+ case IS_STRING: \
+ convert_to_string(pzv); \
+ break; \
+ default: \
+ assert(0); \
+ break; \
+ } \
+ } while (0);
+#endif
+
+static int spl_type_object_cast(zval *zobject, zval *writeobj, int type TSRMLS_DC) /* {{{ */
+{
+ spl_type_object *object = (spl_type_object*)zend_object_store_get_object(zobject TSRMLS_CC);
+
+ ZVAL_ZVAL(writeobj, object->value, 1, 0);
+ convert_to_explicit_type(writeobj, type);
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ proto void SplType::__construct(mixed initial_value [, bool strict])
+ Cronstructs a enum with given value. */
+SPL_METHOD(SplType, __construct)
+{
+ zval *value = NULL;
+ spl_type_object *object;
+
+ object = (spl_type_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ php_set_error_handling(EH_THROW, spl_ce_InvalidArgumentException TSRMLS_CC);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zb", &value, &object->strict) == FAILURE) {
+ php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
+ return;
+ }
+
+ if (ZEND_NUM_ARGS()) {
+ spl_type_object_set(&getThis(), value TSRMLS_CC);
+ }
+
+ php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
+}
+/* }}} */
+
+int spl_enum_apply_get_consts(zval **pzconst, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
+{
+ zval *val;
+ zval *return_value = va_arg(args, zval*);
+ long inc_def = va_arg(args, long);
+ zval **def = va_arg(args, zval**);
+
+ if (inc_def || pzconst != def) {
+ MAKE_STD_ZVAL(val);
+ ZVAL_ZVAL(val, *pzconst, 1, 0);
+#if PHP_MAJOR_VERSION < 6
+ add_assoc_zval(return_value, hash_key->arKey, val);
+#else
+ add_u_assoc_zval_ex(return_value, hash_key->type, hash_key->arKey, hash_key->nKeyLength, val);
+#endif
+ }
+
+ return ZEND_HASH_APPLY_KEEP;
+}
+/* }}} */
+
+/* {{{ proto array SplEnum::getConstList([bool inc_def = false])
+ Returns all consts (possible values) as an array. */
+SPL_METHOD(SplEnum, getConstList)
+{
+ zend_class_entry *ce = Z_OBJCE_P(getThis());
+ long inc_def = 0;
+ zval **def;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &inc_def) == FAILURE) {
+ return;
+ }
+ if (!inc_def) {
+ zend_hash_find(&ce->constants_table, "__default", sizeof("__default"), (void **) &def);
+ }
+
+ zend_update_class_constants(ce TSRMLS_CC);
+ array_init(return_value);
+
+ zend_hash_apply_with_arguments(&ce->constants_table SPL_TYPES_CALLABLE, (apply_func_args_t)spl_enum_apply_get_consts, 3, return_value, inc_def, def);
+}
+/* }}} */
+
+static zend_object_value spl_type_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
+{
+ return spl_type_object_new_ex(class_type, 0, NULL, spl_type_set_enum TSRMLS_CC);
+}
+/* }}} */
+
+static zend_object_value spl_int_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
+{
+ return spl_type_object_new_ex(class_type, 1, NULL, spl_type_set_int TSRMLS_CC);
+}
+/* }}} */
+
+static zend_object_value spl_float_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
+{
+ return spl_type_object_new_ex(class_type, 1, NULL, spl_type_set_float TSRMLS_CC);
+}
+/* }}} */
+
+static zend_object_value spl_string_object_new(zend_class_entry *class_type TSRMLS_DC)
+{
+ return spl_type_object_new_ex(class_type, 1, NULL, spl_type_set_string TSRMLS_CC);
+}
+/* {{{ Method and class definitions */
+ZEND_BEGIN_ARG_INFO_EX(arg_SplType___construct, 0, 0, 0)
+ ZEND_ARG_INFO(0, initial_value)
+ ZEND_ARG_INFO(0, strict)
+ZEND_END_ARG_INFO()
+
+static zend_function_entry spl_funcs_SplType[] = {
+ SPL_ME(SplType, __construct, arg_SplType___construct, ZEND_ACC_PUBLIC)
+ {NULL, NULL, NULL}
+};
+
+ZEND_BEGIN_ARG_INFO_EX(arg_SplEnum_getConstList, 0, 0, 0)
+ ZEND_ARG_INFO(0, include_default)
+ZEND_END_ARG_INFO()
+
+static zend_function_entry spl_funcs_SplEnum[] = {
+ SPL_ME(SplEnum, getConstList, arg_SplEnum_getConstList, ZEND_ACC_PUBLIC)
+ {NULL, NULL, NULL}
+};
+/* }}} */
+
+static zend_object_value spl_enum_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
+{
+ return spl_type_object_new_ex(class_type, 0, NULL, spl_type_set_enum TSRMLS_CC);
+}
+/* }}} */
+
+PHP_MINIT_FUNCTION(spl_type) /* {{{ */
+{
+ REGISTER_SPL_STD_CLASS_EX(SplType, spl_type_object_new, spl_funcs_SplType);
+ memcpy(&spl_handler_SplType, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+
+ spl_handler_SplType.clone_obj = spl_type_object_clone;
+ spl_handler_SplType.get = spl_type_object_get;
+ spl_handler_SplType.set = spl_type_object_set;
+ spl_handler_SplType.get_properties = spl_type_object_get_properties;
+ /**
+ * This is going to be removed and put to spl_type_object_cast soon.
+ * @FIXME
+ * @todo Make sure the custom casting is working well
+ */
+ spl_handler_SplType.cast_object = spl_type_object_cast;
+
+ zend_declare_class_constant_null(spl_ce_SplType, "__default", sizeof("__default") - 1 TSRMLS_CC);
+
+ spl_ce_SplType->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
+
+ REGISTER_SPL_SUB_CLASS_EX(SplEnum, SplType, spl_enum_object_new, spl_funcs_SplEnum);
+ spl_ce_SplEnum->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
+
+ REGISTER_SPL_SUB_CLASS_EX(SplBool, SplEnum, spl_enum_object_new, NULL);
+ zend_declare_class_constant_bool(spl_ce_SplBool, "false", sizeof("false") - 1, 0 TSRMLS_CC);
+ zend_declare_class_constant_bool(spl_ce_SplBool, "true", sizeof("true") - 1, 1 TSRMLS_CC);
+ zend_declare_class_constant_bool(spl_ce_SplBool, "__default", sizeof("__default") - 1, 0 TSRMLS_CC);
+
+ REGISTER_SPL_SUB_CLASS_EX(SplInt, SplType, spl_int_object_new, NULL);
+ zend_declare_class_constant_long(spl_ce_SplInt, "__default", sizeof("__default") - 1, 0 TSRMLS_CC);
+
+ REGISTER_SPL_SUB_CLASS_EX(SplFloat, SplType, spl_float_object_new, NULL);
+ zend_declare_class_constant_double(spl_ce_SplFloat, "__default", sizeof("__default") - 1, 0 TSRMLS_CC);
+
+ REGISTER_SPL_SUB_CLASS_EX(SplString, SplType, spl_string_object_new, NULL);
+ zend_declare_class_constant_string(spl_ce_SplString, "__default", sizeof("__default") - 1, "" TSRMLS_CC);
+
+ return SUCCESS;
+}
+/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: fdm=marker
+ * vim: noet sw=4 ts=4
+ */
64 spl_type.h
@@ -0,0 +1,64 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2008 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Authors: Marcus Boerger <helly@php.net> |
+ +----------------------------------------------------------------------+
+ */
+
+/* $Id: spl_type.h 279980 2009-05-05 15:25:56Z davidc $ */
+
+#ifndef SPL_TYPE_H
+#define SPL_TYPE_H
+
+#include "php.h"
+#include "php_spl_types.h"
+
+
+extern SPL_TYPES_API zend_class_entry *spl_ce_SplType;
+extern SPL_TYPES_API zend_class_entry *spl_ce_SplEnum;
+extern SPL_TYPES_API zend_class_entry *spl_ce_SplBool;
+extern SPL_TYPES_API zend_class_entry *spl_ce_SplInt;
+extern SPL_TYPES_API zend_class_entry *spl_ce_SplFloat;
+extern SPL_TYPES_API zend_class_entry *spl_ce_SplString;
+
+PHP_MINIT_FUNCTION(spl_type);
+
+typedef struct _spl_type_object spl_type_object;
+
+typedef struct _spl_type_set_info {
+ spl_type_object *object;
+ zval *value;
+ int done;
+} spl_type_set_info;
+
+typedef void (*spl_type_set_t)(spl_type_set_info *inf TSRMLS_DC);
+
+struct _spl_type_object {
+ zend_object std;
+ zval *value;
+ zend_bool strict;
+ spl_type_set_t set;
+ HashTable *properties_copy;
+};
+
+#endif /* SPL_TYPE_H */
+
+/*
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim600: fdm=marker
+ * vim: noet sw=4 ts=4
+ */
47 tests/.svn/all-wcprops
@@ -0,0 +1,47 @@
+K 25
+svn:wc:ra_dav:version-url
+V 54
+/repository/!svn/ver/279981/pecl/spl_types/trunk/tests
+END
+006.phpt
+K 25
+svn:wc:ra_dav:version-url
+V 63
+/repository/!svn/ver/214271/pecl/spl_types/trunk/tests/006.phpt
+END
+007.phpt
+K 25
+svn:wc:ra_dav:version-url
+V 63
+/repository/!svn/ver/279981/pecl/spl_types/trunk/tests/007.phpt
+END
+001.phpt
+K 25
+svn:wc:ra_dav:version-url
+V 63
+/repository/!svn/ver/212880/pecl/spl_types/trunk/tests/001.phpt
+END
+002.phpt
+K 25
+svn:wc:ra_dav:version-url
+V 63
+/repository/!svn/ver/212880/pecl/spl_types/trunk/tests/002.phpt
+END
+003.phpt
+K 25
+svn:wc:ra_dav:version-url
+V 63
+/repository/!svn/ver/208793/pecl/spl_types/trunk/tests/003.phpt
+END
+004.phpt
+K 25
+svn:wc:ra_dav:version-url
+V 63
+/repository/!svn/ver/256021/pecl/spl_types/trunk/tests/004.phpt
+END
+005.phpt
+K 25
+svn:wc:ra_dav:version-url
+V 63
+/repository/!svn/ver/209135/pecl/spl_types/trunk/tests/005.phpt
+END
14 tests/.svn/dir-prop-base
@@ -0,0 +1,14 @@
+K 10
+svn:ignore
+V 58
+phpt.*
+*.mem
+*.diff
+*.log
+*.exp
+*.out
+*.php
+*.gcda
+*.gcno
+
+END
266 tests/.svn/entries
@@ -0,0 +1,266 @@
+10
+
+dir
+307562
+http://svn.php.net/repository/pecl/spl_types/trunk/tests
+http://svn.php.net/repository
+
+
+
+2009-05-05T15:33:09.000000Z
+279981
+davidc
+has-props
+
+
+
+
+
+
+
+
+
+
+
+
+
+c90b9560-bf6c-de11-be94-00142212c4b1
+
+006.phpt
+file
+
+
+
+
+2011-01-18T20:20:33.000000Z
+4e9fc9e4b2bfa86997222fda1c7f373d
+2006-06-05T13:58:07.000000Z
+214271
+helly
+has-props
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+1320
+
+007.phpt
+file
+
+
+
+
+2011-01-18T20:20:33.000000Z
+58ef2ba81700a6fa081d20999bf1a60b
+2009-05-05T15:33:09.000000Z
+279981
+davidc
+has-props
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+870
+
+001.phpt
+file
+
+
+
+
+2011-01-18T20:20:33.000000Z
+4a46b399a6d25ab091966391f97bc2ea
+2006-05-11T23:09:51.000000Z
+212880
+helly
+has-props
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+5943
+
+002.phpt
+file
+
+
+
+
+2011-01-18T20:20:33.000000Z
+b4df1dd392c0620efa92db9c18e63310
+2006-05-11T23:09:51.000000Z
+212880
+helly
+has-props
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+2516
+
+003.phpt
+file
+
+
+
+
+2011-01-18T20:20:33.000000Z
+0c33398ba7c771dccb06a80e1171f584
+2006-03-06T21:07:54.000000Z
+208793
+helly
+has-props
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+735
+
+004.phpt
+file
+
+
+
+
+2011-01-18T20:20:33.000000Z
+91ea237837f26da04e8ec45510fee7df
+2008-03-25T01:21:39.000000Z
+256021
+helly
+has-props
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+2173
+
+005.phpt
+file
+
+
+
+
+2011-01-18T20:20:33.000000Z
+6fb5a84f264727e245657947b1fb9f04
+2006-03-11T16:02:44.000000Z
+209135
+helly
+has-props
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+3038
+
17 tests/.svn/prop-base/001.phpt.svn-base
@@ -0,0 +1,17 @@
+K 15
+cvs2svn:cvs-rev
+V 3
+1.2
+K 13
+svn:eol-style
+V 6
+native
+K 14
+svn:executable
+V 1
+*
+K 12
+svn:keywords
+V 89
+Id Rev Revision Date LastChangedDate LastChangedRevision Author LastChangedBy HeadURL URL
+END
17 tests/.svn/prop-base/002.phpt.svn-base
@@ -0,0 +1,17 @@
+K 15
+cvs2svn:cvs-rev
+V 3
+1.2
+K 13
+svn:eol-style
+V 6
+native
+K 14
+svn:executable
+V 1
+*
+K 12
+svn:keywords
+V 89
+Id Rev Revision Date LastChangedDate LastChangedRevision Author LastChangedBy HeadURL URL
+END
17 tests/.svn/prop-base/003.phpt.svn-base
@@ -0,0 +1,17 @@
+K 15
+cvs2svn:cvs-rev
+V 3
+1.1
+K 13
+svn:eol-style
+V 6
+native
+K 14
+svn:executable
+V 1
+*
+K 12
+svn:keywords
+V 89
+Id Rev Revision Date LastChangedDate LastChangedRevision Author LastChangedBy HeadURL URL
+END
17 tests/.svn/prop-base/004.phpt.svn-base
@@ -0,0 +1,17 @@
+K 15
+cvs2svn:cvs-rev
+V 3
+1.3
+K 13
+svn:eol-style
+V 6
+native
+K 14
+svn:executable
+V 1
+*
+K 12
+svn:keywords
+V 89
+Id Rev Revision Date LastChangedDate LastChangedRevision Author LastChangedBy HeadURL URL
+END
17 tests/.svn/prop-base/005.phpt.svn-base
@@ -0,0 +1,17 @@
+K 15
+cvs2svn:cvs-rev
+V 3
+1.1
+K 13
+svn:eol-style
+V 6
+native
+K 14
+svn:executable
+V 1
+*
+K 12
+svn:keywords
+V 89
+Id Rev Revision Date LastChangedDate LastChangedRevision Author LastChangedBy HeadURL URL
+END
17 tests/.svn/prop-base/006.phpt.svn-base
@@ -0,0 +1,17 @@
+K 15
+cvs2svn:cvs-rev
+V 3
+1.2
+K 13
+svn:eol-style
+V 6
+native
+K 14
+svn:executable
+V 1
+*
+K 12
+svn:keywords
+V 89
+Id Rev Revision Date LastChangedDate LastChangedRevision Author LastChangedBy HeadURL URL
+END
17 tests/.svn/prop-base/007.phpt.svn-base
@@ -0,0 +1,17 @@
+K 15
+cvs2svn:cvs-rev
+V 3
+1.1
+K 13
+svn:eol-style
+V 6
+native
+K 14
+svn:executable
+V 1
+*
+K 12
+svn:keywords
+V 89
+Id Rev Revision Date LastChangedDate LastChangedRevision Author LastChangedBy HeadURL URL
+END
444 tests/.svn/text-base/001.phpt.svn-base
@@ -0,0 +1,444 @@
+--TEST--
+SPL: SplEnum
+--SKIPIF--
+<?php if (!extension_loaded("spl_types")) print "skip"; ?>
+<?php if (!extension_loaded("reflection")) print "skip reflection not available"; ?>
+--FILE--
+<?php
+
+class MyIntEnum extends SplEnum
+{
+ const one = 1;
+ const two = 2;
+
+ const __default = MyIntEnum::one;
+}
+
+echo "==INT==\n";
+$r1 = new ReflectionClass('MyIntEnum');
+var_dump($r1->getConstants());
+
+echo "==NEW==\n";
+$e1 = new MyIntEnum;
+var_dump($e1);
+echo "$e1\n";
+
+echo "==ASSIGN==\n";
+$x1 = $e1;
+var_dump($x1);
+echo "$x1\n";
+$y1 = "Bar" . $e1;
+
+echo "==CHANGE==\n";
+$e1 = 2;
+var_dump($e1);
+echo "$e1\n";
+
+echo "==ADD==\n";
+$y1 = 2 + $e1;
+var_dump($y1);
+echo "$y1\n";
+
+echo "==CONCAT==\n";
+$y1 = "Wee" . $e1;
+var_dump($y1);
+echo "$y1\n";
+
+echo "==CONV==\n";
+$e1 = "2";
+var_dump($e1);
+echo "$e1\n";
+
+echo "==FAIL==\n";
+try
+{
+ $e1 = 7;
+}
+catch(UnexpectedValueException $err)
+{
+ var_dump($err->getMessage());
+}
+var_dump($e1);
+echo "$e1\n";
+
+class MyStrEnum extends SplEnum
+{
+ const foo = "Foo";
+ const bar = "Bar";
+ const __default = MyStrEnum::foo;
+}
+
+echo "==STR==\n";
+$r2 = new ReflectionClass('MyStrEnum');
+var_dump($r2->getConstants());
+
+echo "==NEW==\n";
+$e2 = new MyStrEnum;
+var_dump($e2);
+echo "$e2\n";
+
+echo "==ASSIGN==\n";
+$x2 = $e2;
+var_dump($x2);
+echo "$x2\n";
+
+echo "==CHANGE==\n";
+$e2 = "Bar";
+var_dump($e2);
+echo "$e2\n";
+
+echo "==ADD==\n";
+$y2 = 2 + $e2;
+var_dump($y2);
+echo "$y2\n";
+
+echo "==CONCAT==\n";
+$y2 = "Wee" . $e2;
+var_dump($y2);
+echo "$y2\n";
+
+echo "==FAIL==\n";
+try
+{
+ $e2 = "Baz";
+}
+catch(UnexpectedValueException $err)
+{
+ var_dump($err->getMessage());
+}
+var_dump($e2);
+echo "$e2\n";
+
+echo "==EXTEND==\n";
+
+class MyStrEnumEx extends MyStrEnum
+{
+ const bar = "Baz";
+ const bla = "Bla";
+ const __default = "def";
+}
+
+echo "==STR==\n";
+$r3 = new ReflectionClass('MyStrEnumEx');
+var_dump($r3->getConstants());
+
+echo "==NEW==\n";
+$e3 = new MyStrEnumEx;
+var_dump($e3);
+echo "$e3\n";
+
+echo "==ASSIGN==\n";
+$x3 = $e3;
+var_dump($x3);
+echo "$x3\n";
+
+echo "==CHANGE==\n";
+$e3 = "def";
+var_dump($e3);
+echo "$e3\n";
+
+echo "==ADD==\n";
+$y3 = 3 + $e3;
+var_dump($y3);
+echo "$y3\n";
+
+echo "==CONCAT==\n";
+$y3 = "Bar" . $e3;
+var_dump($y3);
+echo "$y3\n";
+
+echo "==FAIL==\n";
+try
+{
+ $e3 = "Bar";
+}
+catch(UnexpectedValueException $err)
+{
+ var_dump($err->getMessage());
+}
+var_dump($e3);
+echo "$e3\n";
+
+echo "==ASSIGN==\n";
+$e2 = "Foo";
+$e3 = $e2;
+var_dump($e3);
+echo "$e3\n";
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+==INT==
+array(3) {
+ ["one"]=>
+ int(1)
+ ["two"]=>
+ int(2)
+ ["__default"]=>
+ int(1)
+}
+==NEW==
+object(MyIntEnum)#%d (1) {
+ ["__default"]=>
+ int(1)
+}
+1
+==ASSIGN==
+object(MyIntEnum)#%d (1) {
+ ["__default"]=>
+ int(1)
+}
+1
+==CHANGE==
+object(MyIntEnum)#%d (1) {
+ ["__default"]=>
+ int(2)
+}
+2
+==ADD==
+int(4)
+4
+==CONCAT==
+string(4) "Wee2"
+Wee2
+==CONV==
+object(MyIntEnum)#%d (1) {
+ ["__default"]=>
+ int(2)
+}
+2
+==FAIL==
+string(35) "Value not a const in enum MyIntEnum"
+object(MyIntEnum)#%d (1) {
+ ["__default"]=>
+ int(2)
+}
+2
+==STR==
+array(3) {
+ ["foo"]=>
+ string(3) "Foo"
+ ["bar"]=>
+ string(3) "Bar"
+ ["__default"]=>
+ string(3) "Foo"
+}
+==NEW==
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ string(3) "Foo"
+}
+Foo
+==ASSIGN==
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ string(3) "Foo"
+}
+Foo
+==CHANGE==
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ string(3) "Bar"
+}
+Bar
+==ADD==
+int(2)
+2
+==CONCAT==
+string(6) "WeeBar"
+WeeBar
+==FAIL==
+string(35) "Value not a const in enum MyStrEnum"
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ string(3) "Bar"
+}
+Bar
+==EXTEND==
+==STR==
+array(4) {
+ ["bar"]=>
+ string(3) "Baz"
+ ["bla"]=>
+ string(3) "Bla"
+ ["__default"]=>
+ string(3) "def"
+ ["foo"]=>
+ string(3) "Foo"
+}
+==NEW==
+object(MyStrEnumEx)#%d (1) {
+ ["__default"]=>
+ string(3) "def"
+}
+def
+==ASSIGN==
+object(MyStrEnumEx)#%d (1) {
+ ["__default"]=>
+ string(3) "def"
+}
+def
+==CHANGE==
+object(MyStrEnumEx)#%d (1) {
+ ["__default"]=>
+ string(3) "def"
+}
+def
+==ADD==
+int(3)
+3
+==CONCAT==
+string(6) "Bardef"
+Bardef
+==FAIL==
+string(37) "Value not a const in enum MyStrEnumEx"
+object(MyStrEnumEx)#%d (1) {
+ ["__default"]=>
+ string(3) "def"
+}
+def
+==ASSIGN==
+object(MyStrEnumEx)#%d (1) {
+ ["__default"]=>
+ string(3) "Foo"
+}
+Foo
+===DONE===
+--UEXPECTF--
+==INT==
+array(3) {
+ [u"one"]=>
+ int(1)
+ [u"two"]=>
+ int(2)
+ [u"__default"]=>
+ int(1)
+}
+==NEW==
+object(MyIntEnum)#%d (1) {
+ ["__default"]=>
+ int(1)
+}
+1
+==ASSIGN==
+object(MyIntEnum)#%d (1) {
+ ["__default"]=>
+ int(1)
+}
+1
+==CHANGE==
+object(MyIntEnum)#%d (1) {
+ ["__default"]=>
+ int(2)
+}
+2
+==ADD==
+int(4)
+4
+==CONCAT==
+unicode(4) "Wee2"
+Wee2
+==CONV==
+object(MyIntEnum)#%d (1) {
+ ["__default"]=>
+ int(2)
+}
+2
+==FAIL==
+unicode(35) "Value not a const in enum MyIntEnum"
+object(MyIntEnum)#%d (1) {
+ ["__default"]=>
+ int(2)
+}
+2
+==STR==
+array(3) {
+ [u"foo"]=>
+ unicode(3) "Foo"
+ [u"bar"]=>
+ unicode(3) "Bar"
+ [u"__default"]=>
+ unicode(3) "Foo"
+}
+==NEW==
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ unicode(3) "Foo"
+}
+Foo
+==ASSIGN==
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ unicode(3) "Foo"
+}
+Foo
+==CHANGE==
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ unicode(3) "Bar"
+}
+Bar
+==ADD==
+int(2)
+2
+==CONCAT==
+unicode(6) "WeeBar"
+WeeBar
+==FAIL==
+unicode(35) "Value not a const in enum MyStrEnum"
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ unicode(3) "Bar"
+}
+Bar
+==EXTEND==
+==STR==
+array(4) {
+ [u"bar"]=>
+ unicode(3) "Baz"
+ [u"bla"]=>
+ unicode(3) "Bla"
+ [u"__default"]=>
+ unicode(3) "def"
+ [u"foo"]=>
+ unicode(3) "Foo"
+}
+==NEW==
+object(MyStrEnumEx)#%d (1) {
+ ["__default"]=>
+ unicode(3) "def"
+}
+def
+==ASSIGN==
+object(MyStrEnumEx)#%d (1) {
+ ["__default"]=>
+ unicode(3) "def"
+}
+def
+==CHANGE==
+object(MyStrEnumEx)#%d (1) {
+ ["__default"]=>
+ unicode(3) "def"
+}
+def
+==ADD==
+int(3)
+3
+==CONCAT==
+unicode(6) "Bardef"
+Bardef
+==FAIL==
+unicode(37) "Value not a const in enum MyStrEnumEx"
+object(MyStrEnumEx)#%d (1) {
+ ["__default"]=>
+ unicode(3) "def"
+}
+def
+==ASSIGN==
+object(MyStrEnumEx)#%d (1) {
+ ["__default"]=>
+ unicode(3) "Foo"
+}
+Foo
+===DONE===
185 tests/.svn/text-base/002.phpt.svn-base
@@ -0,0 +1,185 @@
+--TEST--
+SPL: SplEnum, strict mode
+--SKIPIF--
+<?php if (!extension_loaded("spl_types")) print "skip"; ?>
+--FILE--
+<?php
+
+class MyIntEnum extends SplEnum
+{
+ const one = 1;
+ const two = 2;
+
+ const __default = MyIntEnum::one;
+
+ function __construct()
+ {
+ parent::__construct(self::__default, true);
+ }
+}
+
+echo "==NEW==\n";
+$e1 = new MyIntEnum;
+var_dump($e1);
+echo "$e1\n";
+
+echo "==PASS==\n";
+$e1 = 1;
+var_dump($e1);
+echo "$e1\n";
+$e1 = 2;
+var_dump($e1);
+echo "$e1\n";
+
+echo "==FAIL==\n";
+try
+{
+ $e1 = "2";
+}
+catch(UnexpectedValueException $err)
+{
+ var_dump($err->getMessage());
+}
+var_dump($e1);
+echo "$e1\n";
+
+class MyStrEnum extends SplEnum
+{
+ const foo = "Foo";
+ const bar = "Bar";
+ const __default = MyStrEnum::foo;
+
+ function __construct()
+ {
+ parent::__construct(self::__default, true);
+ }
+}
+
+echo "==NEW==\n";
+$e2 = new MyStrEnum;
+var_dump($e2);
+echo "$e2\n";
+
+echo "==PASS==\n";
+$e2 = "Bar";
+var_dump($e2);
+echo "$e2\n";
+$e2 = "Foo";
+var_dump($e2);
+echo "$e2\n";
+
+echo "==FAIL==\n";
+try
+{
+ $e2 = "Baz";
+}
+catch(UnexpectedValueException $err)
+{
+ var_dump($err->getMessage());
+}
+var_dump($e2);
+echo "$e2\n";
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+==NEW==
+object(MyIntEnum)#%d (1) {
+ ["__default"]=>
+ int(1)
+}
+1
+==PASS==
+object(MyIntEnum)#%d (1) {
+ ["__default"]=>
+ int(1)
+}
+1
+object(MyIntEnum)#%d (1) {
+ ["__default"]=>
+ int(2)
+}
+2
+==FAIL==
+string(35) "Value not a const in enum MyIntEnum"
+object(MyIntEnum)#%d (1) {
+ ["__default"]=>
+ int(2)
+}
+2
+==NEW==
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ string(3) "Foo"
+}
+Foo
+==PASS==
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ string(3) "Bar"
+}
+Bar
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ string(3) "Foo"
+}
+Foo
+==FAIL==
+string(35) "Value not a const in enum MyStrEnum"
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ string(3) "Foo"
+}
+Foo
+===DONE===
+--UEXPECTF--
+==NEW==
+object(MyIntEnum)#%d (1) {
+ ["__default"]=>
+ int(1)
+}
+1
+==PASS==
+object(MyIntEnum)#%d (1) {
+ ["__default"]=>
+ int(1)
+}
+1
+object(MyIntEnum)#%d (1) {
+ ["__default"]=>
+ int(2)
+}
+2
+==FAIL==
+unicode(35) "Value not a const in enum MyIntEnum"
+object(MyIntEnum)#%d (1) {
+ ["__default"]=>
+ int(2)
+}
+2
+==NEW==
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ unicode(3) "Foo"
+}
+Foo
+==PASS==
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ unicode(3) "Bar"
+}
+Bar
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ unicode(3) "Foo"
+}
+Foo
+==FAIL==
+unicode(35) "Value not a const in enum MyStrEnum"
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ unicode(3) "Foo"
+}
+Foo
+===DONE===
60 tests/.svn/text-base/003.phpt.svn-base
@@ -0,0 +1,60 @@
+--TEST--
+SPL: SplBool
+--SKIPIF--
+<?php if (!extension_loaded("spl_types")) print "skip"; ?>
+--FILE--
+<?php
+
+echo "==NEW==\n";
+$e1 = new SplBool;
+var_dump($e1);
+echo "$e1\n";
+
+echo "==PASS==\n";
+$e1 = 1;
+var_dump($e1);
+echo "$e1\n";
+$e1 = 0;
+var_dump($e1);
+echo "$e1\n";
+
+echo "==FAIL==\n";
+try
+{
+ $e1 = "xyz";
+}
+catch(UnexpectedValueException $err)
+{
+ var_dump($err->getMessage());
+}
+var_dump($e1);
+echo "$e1\n";
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+==NEW==
+object(SplBool)#%d (1) {
+ ["__default"]=>
+ bool(false)
+}
+
+==PASS==
+object(SplBool)#%d (1) {
+ ["__default"]=>
+ bool(true)
+}
+1
+object(SplBool)#%d (1) {
+ ["__default"]=>
+ bool(false)
+}
+
+==FAIL==
+object(SplBool)#%d (1) {
+ ["__default"]=>
+ bool(true)
+}
+1
+===DONE===
166 tests/.svn/text-base/004.phpt.svn-base
@@ -0,0 +1,166 @@
+--TEST--
+SPL: SplInt
+--SKIPIF--
+<?php if (!extension_loaded("spl_types")) print "skip"; ?>
+--FILE--
+<?php
+
+echo "==NEW==\n";
+$e1 = new SplInt;
+var_dump($e1);
+echo "$e1\n";
+
+echo "==PASS==\n";
+$e1 = 1;
+var_dump($e1);
+echo "$e1\n";
+$e1 = 0;
+var_dump($e1);
+echo "$e1\n";
+
+echo "==STRING==\n";
+try
+{
+ $e1 = "xyz";
+}
+catch(UnexpectedValueException $err)
+{
+ var_dump($err->getMessage());
+}
+var_dump($e1);
+echo "$e1\n";
+
+echo "==FAIL==\n";
+$e2 = new SplInt(0, true);
+try
+{
+ $e2 = "xyz";
+}
+catch(UnexpectedValueException $err)
+{
+ var_dump($err->getMessage());
+}
+var_dump($e2);
+echo "$e2\n";
+
+echo "===STRICT:1<2==\n"; // not getting strict
+$e3 = new SplInt(0, false);
+try
+{
+ $e3 = "xyz";
+}
+catch(UnexpectedValueException $err)
+{
+ var_dump($err->getMessage());
+}
+var_dump($e3);
+echo "$e3\n";
+
+echo "===STRICT:2>1==\n"; // staying strict
+$e4 = new SplInt(0, true);
+try
+{
+ $e4 = "xyz";
+}
+catch(UnexpectedValueException $err)
+{
+ var_dump($err->getMessage());
+}
+var_dump($e4);
+echo "$e4\n";
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+==NEW==
+object(SplInt)#%d (1) {
+ ["__default"]=>
+ int(0)
+}
+0
+==PASS==
+object(SplInt)#%d (1) {
+ ["__default"]=>
+ int(1)
+}
+1
+object(SplInt)#%d (1) {
+ ["__default"]=>
+ int(0)
+}
+0
+==STRING==
+string(20) "Value not an integer"
+object(SplInt)#%d (1) {
+ ["__default"]=>
+ int(0)
+}
+0
+==FAIL==
+string(20) "Value not an integer"
+object(SplInt)#%d (1) {
+ ["__default"]=>
+ int(0)
+}
+0
+===STRICT:1<2==
+object(SplInt)#%d (1) {
+ ["__default"]=>
+ int(0)
+}
+0
+===STRICT:2>1==
+string(20) "Value not an integer"
+object(SplInt)#%d (1) {
+ ["__default"]=>
+ int(0)
+}
+0
+===DONE===
+--UEXPECTF--
+==NEW==
+object(SplInt)#%d (1) {
+ ["__default"]=>
+ int(0)
+}
+0
+==PASS==
+object(SplInt)#%d (1) {
+ ["__default"]=>
+ int(1)
+}
+1
+object(SplInt)#%d (1) {
+ ["__default"]=>
+ int(0)
+}
+0
+==STRING==
+unicode(20) "Value not an integer"
+object(SplInt)#%d (1) {
+ ["__default"]=>
+ int(0)
+}
+0
+==FAIL==
+unicode(20) "Value not an integer"
+object(SplInt)#%d (1) {
+ ["__default"]=>
+ int(0)
+}
+0
+===STRICT:1<2==
+object(SplInt)#%d (1) {
+ ["__default"]=>
+ int(0)
+}
+0
+===STRICT:2>1==
+unicode(20) "Value not an integer"
+object(SplInt)#%d (1) {
+ ["__default"]=>
+ int(0)
+}
+0
+===DONE===
219 tests/.svn/text-base/005.phpt.svn-base
@@ -0,0 +1,219 @@
+--TEST--
+SPL: SplEnum::getConstList()
+--SKIPIF--
+<?php if (!extension_loaded("spl_types")) print "skip"; ?>
+<?php if (!extension_loaded("reflection")) print "skip reflection not available"; ?>
+--FILE--
+<?php
+
+function test($cname)
+{
+ echo "===$cname===\n";
+ eval('$x = new '.$cname.'; var_dump($x->getConstList());');
+ eval('$x = new '.$cname.'; var_dump($x->getConstList(true));');
+}
+
+test('SplBool');
+
+class MyIntEnum extends SplEnum
+{
+ const one = 1;
+ const two = 2;
+
+ const __default = MyIntEnum::one;
+}
+
+test('MyIntEnum');
+
+class MyStrEnum extends SplEnum
+{
+ const foo = "Foo";
+ const bar = "Bar";
+ const __default = MyStrEnum::foo;
+}
+
+test('MyStrEnum');
+
+class MyStrEnumEx extends MyStrEnum
+{
+ const bar = "Baz";
+ const bla = "Bla";
+ const __default = "def";
+}
+
+test('MyStrEnumEx');
+test('MyStrEnumEx');
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECT--
+===SplBool===
+array(2) {
+ ["false"]=>
+ bool(false)
+ ["true"]=>
+ bool(true)
+}
+array(3) {
+ ["__default"]=>
+ bool(false)
+ ["false"]=>
+ bool(false)
+ ["true"]=>
+ bool(true)
+}
+===MyIntEnum===
+array(2) {
+ ["one"]=>
+ int(1)
+ ["two"]=>
+ int(2)
+}
+array(3) {
+ ["one"]=>
+ int(1)
+ ["two"]=>
+ int(2)
+ ["__default"]=>
+ int(1)
+}
+===MyStrEnum===
+array(2) {
+ ["foo"]=>
+ string(3) "Foo"
+ ["bar"]=>
+ string(3) "Bar"
+}
+array(3) {
+ ["foo"]=>
+ string(3) "Foo"
+ ["bar"]=>
+ string(3) "Bar"
+ ["__default"]=>
+ string(3) "Foo"
+}
+===MyStrEnumEx===
+array(3) {
+ ["bar"]=>
+ string(3) "Baz"
+ ["bla"]=>
+ string(3) "Bla"
+ ["foo"]=>
+ string(3) "Foo"
+}
+array(4) {
+ ["bar"]=>
+ string(3) "Baz"
+ ["bla"]=>
+ string(3) "Bla"
+ ["__default"]=>
+ string(3) "def"
+ ["foo"]=>
+ string(3) "Foo"
+}
+===MyStrEnumEx===
+array(3) {
+ ["bar"]=>
+ string(3) "Baz"
+ ["bla"]=>
+ string(3) "Bla"
+ ["foo"]=>
+ string(3) "Foo"
+}
+array(4) {
+ ["bar"]=>
+ string(3) "Baz"
+ ["bla"]=>
+ string(3) "Bla"
+ ["__default"]=>
+ string(3) "def"
+ ["foo"]=>
+ string(3) "Foo"
+}
+===DONE===
+--UEXPECT--
+===SplBool===
+array(2) {
+ [u"false"]=>
+ bool(false)
+ [u"true"]=>
+ bool(true)
+}
+array(3) {
+ [u"__default"]=>
+ bool(false)
+ [u"false"]=>
+ bool(false)
+ [u"true"]=>
+ bool(true)
+}
+===MyIntEnum===
+array(2) {
+ [u"one"]=>
+ int(1)
+ [u"two"]=>
+ int(2)
+}
+array(3) {
+ [u"one"]=>
+ int(1)
+ [u"two"]=>
+ int(2)
+ [u"__default"]=>
+ int(1)
+}
+===MyStrEnum===
+array(2) {
+ [u"foo"]=>
+ unicode(3) "Foo"
+ [u"bar"]=>
+ unicode(3) "Bar"
+}
+array(3) {
+ [u"foo"]=>
+ unicode(3) "Foo"
+ [u"bar"]=>
+ unicode(3) "Bar"
+ [u"__default"]=>
+ unicode(3) "Foo"
+}
+===MyStrEnumEx===
+array(3) {
+ [u"bar"]=>
+ unicode(3) "Baz"
+ [u"bla"]=>
+ unicode(3) "Bla"
+ [u"foo"]=>
+ unicode(3) "Foo"
+}
+array(4) {
+ [u"bar"]=>
+ unicode(3) "Baz"
+ [u"bla"]=>
+ unicode(3) "Bla"
+ [u"__default"]=>
+ unicode(3) "def"
+ [u"foo"]=>
+ unicode(3) "Foo"
+}
+===MyStrEnumEx===
+array(3) {
+ [u"bar"]=>
+ unicode(3) "Baz"
+ [u"bla"]=>
+ unicode(3) "Bla"
+ [u"foo"]=>
+ unicode(3) "Foo"
+}
+array(4) {
+ [u"bar"]=>
+ unicode(3) "Baz"
+ [u"bla"]=>
+ unicode(3) "Bla"
+ [u"__default"]=>
+ unicode(3) "def"
+ [u"foo"]=>
+ unicode(3) "Foo"
+}
+===DONE===
60 tests/.svn/text-base/006.phpt.svn-base
@@ -0,0 +1,60 @@
+--TEST--
+SPL: SplEnum with strings and new parameter parsing api
+--SKIPIF--
+<?php if (!extension_loaded("spl_types")) die("skip"); ?>
+<?php if (version_compare(PHP_VERSION, "5.2", "<")) die("skip requires 5.2"); ?>
+--FILE--
+<?php
+
+class MyStrEnum extends SplEnum
+{
+ const text = "The quick brown fox jumped over the lazy dog.";
+ const __default = MyStrEnum::text;
+
+ function __construct()
+ {
+ parent::__construct(self::__default, true);
+ }
+}
+
+$e = new MyStrEnum;
+var_dump($e);
+var_dump(wordwrap($e, 20, "|\n"));
+var_dump($e);
+var_dump(wordwrap($e, 20, "|\n"));
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ string(45) "The quick brown fox jumped over the lazy dog."
+}
+string(47) "The quick brown fox|
+jumped over the lazy|
+dog."
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ string(45) "The quick brown fox jumped over the lazy dog."
+}
+string(47) "The quick brown fox|
+jumped over the lazy|
+dog."
+===DONE===
+--UEXPECTF--
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ unicode(45) "The quick brown fox jumped over the lazy dog."
+}
+string(47) "The quick brown fox|
+jumped over the lazy|
+dog."
+object(MyStrEnum)#%d (1) {
+ ["__default"]=>
+ unicode(45) "The quick brown fox jumped over the lazy dog."
+}
+string(47) "The quick brown fox|
+jumped over the lazy|
+dog."
+===DONE===
61 tests/.svn/text-base/007.phpt.svn-base
@@ -0,0 +1,61 @@
+--TEST--
+SPL: SplString
+--SKIPIF--
+<?php if (!extension_loaded("spl_types")) print "skip"; ?>
+--FILE--
+<?php
+
+echo "==NEW==\n";
+$e1 = new SplString();
+var_dump($e1);
+echo "$e1\n";
+
+echo "==PASS==\n";
+$e1 = "String";
+var_dump($e1);
+echo "$e1\n";
+$e1 = "Second String";
+var_dump($e1);
+echo "$e1\n";
+
+echo "==FAIL==\n";
+try
+{
+ $e1 = array();
+}
+catch(UnexpectedValueException $err)
+{
+ var_dump($err->getMessage());
+}
+var_dump($e1);
+echo "$e1\n";
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+==NEW==
+object(SplString)#1 (1) {
+ ["__default"]=>
+ string(0) ""
+}
+
+==PASS==
+object(SplString)#1 (1) {
+ ["__default"]=>
+ string(6) "String"
+}
+String
+object(SplString)#1 (1) {
+ ["__default"]=>
+ string(13) "Second String"
+}
+Second String
+==FAIL==
+string(18) "Value not a string"
+object(SplString)#1 (1) {
+ ["__default"]=>
+ string(13) "Second String"
+}
+Second String
+===DONE===
444 tests/001.phpt
<
@@ -0,0 +1,444 @@
+--TEST--
+SPL: SplEnum
+--SKIPIF--
+<?php if (!extension_loaded("spl_types")) print "skip"; ?>
+<?php if (!extension_loaded("reflection")) print "skip reflection not available"; ?>
+--FILE--
+<?php
+
+class MyIntEnum extends SplEnum
+{
+ const one = 1;
+ const two = 2;
+
+ const __default = MyIntEnum::one;
+}
+
+echo "==INT==\n";
+$r1 = new ReflectionClass('MyIntEnum');
+var_dump($r1->getConstants());
+
+echo "==NEW==\n";
+$e1 = new MyIntEnum;
+var_dump($e1);
+echo "$e1\n";
+
+echo "==ASSIGN==\n";
+$x1 = $e1;
+var_dump($x1);
+echo "$x1\n";
+$y1 = "Bar" . $e1;
+
+echo "==CHANGE==\n";
+$e1 = 2;
+var_dump($e1);
+echo "$e1\n";
+
+echo "==ADD==\n";
+$y1 = 2 + $e1;
+var_dump($y1);
+echo "$y1\n";
+
+echo "==CONCAT==\n";
+$y1 = "Wee" . $e1;
+var_dump($y1);
+echo "$y1\n";
+
+echo "==CONV==\n";
+$e1 = "2";
+var_dump($e1);
+echo "$e1\n";
+
+echo "==FAIL==\n";
+try
+{
+ $e1 = 7;
+}
+catch(UnexpectedValueException $err)
+{
+ var_dump($err->getMessage());
+}
+var_dump($e1);
+echo "$e1\n";
+
+class MyStrEnum extends SplEnum
+{
+ const foo = "Foo";
+ const bar = "Bar";
+ const __default = MyStrEnum::foo;
+}
+
+echo "==STR==\n";
+$r2 = new ReflectionClass('MyStrEnum');
+var_dump($r2->getConstants());
+
+echo "==NEW==\n";
+$e2 = new MyStrEnum;
+var_dump($e2);
+echo "$e2\n";
+
+echo "==ASSIGN==\n";
+$x2 = $e2;
+var_dump($x2);
+echo "$x2\n";
+
+echo "==CHANGE==\n";
+$e2 = "Bar";
+var_dump($e2);
+echo "$e2\n";
+
+echo "==ADD==\n";
+$y2 = 2 + $e2;
+var_dump($y2);
+echo "$y2\n";
+
+echo "==CONCAT==\n";
+$y2 = "Wee" . $e2;
+var_dump($y2);
+echo "$y2\n";
+
+echo "==FAIL==\n";
+try
+{
+ $e2 = "Baz";
+}
+catch(UnexpectedValueException $err)
+{
+ var_dump($err->getMessage());
+}
+var_dump($e2);
+echo "$e2\n";
+
+echo "==EXTEND==\n";
+
+class MyStrEnumEx extends MyStrEnum
+{
+ const bar = "Baz";
+ const bla = "Bla";
+ const __default = "def";
+}
+
+echo "==STR==\n";
+$r3 = new ReflectionClass('MyStrEnumEx');