Skip to content

Commit

Permalink
支持 PHP7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Apr 11, 2019
1 parent 910e533 commit 6b64953
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
54 changes: 51 additions & 3 deletions src/base.cc
Expand Up @@ -66,6 +66,7 @@ void echo(const char *format, ...)
va_end(args);
}

#if PHP_VERSION_ID < 70300
static int validate_constant_array(HashTable *ht) /* {{{ */
{
int ret = 1;
Expand Down Expand Up @@ -106,6 +107,48 @@ static int validate_constant_array(HashTable *ht) /* {{{ */
ht->u.v.nApplyCount--;
return ret;
}
#else
static int validate_constant_array(HashTable *ht)
{
int ret = 1;
zval *val;

GC_PROTECT_RECURSION(ht);
ZEND_HASH_FOREACH_VAL_IND(ht, val)
{
ZVAL_DEREF(val);
if (Z_REFCOUNTED_P(val))
{
if (Z_TYPE_P(val) == IS_ARRAY)
{
if (Z_REFCOUNTED_P(val))
{
if (Z_IS_RECURSIVE_P(val))
{
zend_error(E_WARNING, "Constants cannot be recursive arrays");
ret = 0;
break;
}
else if (!validate_constant_array(Z_ARRVAL_P(val)))
{
ret = 0;
break;
}
}
}
else if (Z_TYPE_P(val) != IS_STRING && Z_TYPE_P(val) != IS_RESOURCE)
{
zend_error(E_WARNING, "Constants may only evaluate to scalar values, arrays or resources");
ret = 0;
break;
}
}
}
ZEND_HASH_FOREACH_END();
GC_UNPROTECT_RECURSION(ht);
return ret;
}
#endif

static void copy_constant_array(zval *dst, zval *src) /* {{{ */
{
Expand Down Expand Up @@ -208,9 +251,12 @@ bool define(const char *name, const Variant &v, bool case_sensitive)

ZVAL_COPY(&c.value, val);
zval_ptr_dtor(&val_free);
register_constant: c.flags = case_sensitive ? CONST_CS : 0; /* non persistent */
c.name = zend_string_init(name, len, 0);
register_constant:
#if PHP_VERSION_ID < 70300
c.flags = case_sensitive ? CONST_CS : 0; /* non persistent */
c.module_number = PHP_USER_CONSTANT;
#endif
c.name = zend_string_init(name, len, 0);
if (zend_register_constant(&c) == SUCCESS)
{
return true;
Expand Down Expand Up @@ -338,8 +384,10 @@ static inline ZEND_RESULT_CODE _check_args_num(zend_execute_data *data, int num_
zend_wrong_paramers_count_error(num_args, min_num_args, max_num_args);
#elif PHP_MINOR_VERSION == 1
zend_wrong_parameters_count_error(num_args, min_num_args, max_num_args);
#else
#elif PHP_MINOR_VERSION == 2
zend_wrong_parameters_count_error(1, num_args, min_num_args, max_num_args);
#else
zend_wrong_parameters_count_error(min_num_args, max_num_args);
#endif
return FAILURE;
}
Expand Down
4 changes: 4 additions & 0 deletions src/class.cc
Expand Up @@ -223,7 +223,11 @@ bool Class::activate()
for (int i = 0; i < aliases.size(); i++)
{
string alias = aliases[i];
#if PHP_VERSION_ID > 70300
if (zend_register_class_alias_ex(alias.c_str(), alias.length(), ce, 1) < 0)
#else
if (zend_register_class_alias_ex(alias.c_str(), alias.length(), ce) < 0)
#endif
{
return false;
}
Expand Down
6 changes: 5 additions & 1 deletion src/string.cc
Expand Up @@ -100,7 +100,11 @@ void String::stripTags(String &allow, bool allow_tag_spaces)

String String::addSlashes()
{
return php_addslashes(value, false);
#if PHP_VERSION_ID > 70300
return php_addslashes(value);
#else
return php_addslashes(value, false);
#endif
}

String String::basename(String &suffix)
Expand Down

0 comments on commit 6b64953

Please sign in to comment.