From 51f1d74a2279276ce762056856767b7dc140dd5b Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Fri, 4 Apr 2014 17:33:12 +0200 Subject: fixes to make the library compile for php 5.6 environments (problem discovered in issue #59) --- src/argument.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++-- src/callable.cpp | 12 +++++++++++- src/iterator.cpp | 4 ++-- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/src/argument.cpp b/src/argument.cpp index 8690a5c..a2aa8d5 100644 --- a/src/argument.cpp +++ b/src/argument.cpp @@ -28,13 +28,32 @@ Argument::Argument(const char *name, Type type, bool required, bool byref) // fill members _info->name = name; _info->name_len = strlen(name); -#if PHP_VERSION_ID >= 50400 + +#if PHP_VERSION_ID >= 50400 + + // since php 5.4 there is a type-hint _info->type_hint = (unsigned char)(type == Type::Array || type == Type::Callable ? type : Type::Null); + +# if PHP_VERSION_ID >= 50600 + + // from PHP 5.6 and onwards, an is_variadic property can be set, this + // specifies whether this argument is the first argument that specifies + // the type for a variable length list of arguments. For now we only + // support methods and functions with a fixed number of arguments. + _info->is_variadic = false; + +# endif + #else + + // php 5.3 code _info->array_type_hint = type == Type::Array; _info->return_reference = false; _info->required_num_args = 0; // @todo is this correct? + #endif + + // this parameter is a regular type _info->class_name = NULL; _info->class_name_len = 0; _info->allow_null = false; @@ -60,9 +79,32 @@ Argument::Argument(const char *name, const char *classname, bool nullable, bool // fill members _info->name = name; _info->name_len = strlen(name); -#if PHP_VERSION_ID >= 50400 + +#if PHP_VERSION_ID >= 50400 + + // since php 5.4 there is a type hint _info->type_hint = (unsigned char)Type::Object; + +# if PHP_VERSION_ID >= 50600 + + // from PHP 5.6 and onwards, an is_variadic property can be set, this + // specifies whether this argument is the first argument that specifies + // the type for a variable length list of arguments. For now we only + // support methods and functions with a fixed number of arguments. + _info->is_variadic = false; + +# endif + +#else + + // php 5.3 code + _info->array_type_hint = false; + _info->return_reference = false; + _info->required_num_args = 0; // @todo is this correct? + #endif + + // the parameter is a class _info->class_name = classname; _info->class_name_len = strlen(classname); _info->allow_null = nullable; diff --git a/src/callable.cpp b/src/callable.cpp index 55f2833..5e37df7 100644 --- a/src/callable.cpp +++ b/src/callable.cpp @@ -99,8 +99,18 @@ void Callable::initialize(zend_arg_info *info, const char *classname) const // we do not support return-by-reference finfo->return_reference = false; - // passing by reference is not used +# if PHP_VERSION_ID >= 50600 + // since php 5.6 there are _allow_null and _is_variadic properties. It's + // not exactly clear what they do (@todo find this out) so for now we set + // them to false + finfo->_allow_null = false; + finfo->_is_variadic = false; + +# else + // passing by reference is not used (only for php 5.4 and php 5.5) finfo->pass_rest_by_reference = false; +# endif + #else // php 5.3 code info->name = nullptr; diff --git a/src/iterator.cpp b/src/iterator.cpp index 6242440..0362fb1 100644 --- a/src/iterator.cpp +++ b/src/iterator.cpp @@ -83,10 +83,10 @@ void Iterator::key(zend_object_iterator *iter, zval *key TSRMLS_DC) Value retval(iterator->key()); // detach the underlying zval - zval *zval = retval.detach(); + zval *val = retval.detach(); // copy it to the key - ZVAL_ZVAL(key, zval, 1, 1); + ZVAL_ZVAL(key, val, 1, 1); } /** -- cgit v1.2.3