summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Watkins <krakjoe@php.net>2019-06-11 10:45:41 +0200
committerJoe Watkins <krakjoe@php.net>2019-06-11 10:45:41 +0200
commite52f63bea350ae1169dc873e8e0363271d85d153 (patch)
treec4ecf72b050d061831333d292ebf8bd28fcd12a4
parent3ef151127fc7d7496c0d392b2102609ba0837888 (diff)
parenteecd8961d94c50cc6cdc94ec80df8c1ce4881a76 (diff)
downloadphp-git-e52f63bea350ae1169dc873e8e0363271d85d153.tar.gz
Merge branch 'PHP-7.4' of git://github.com/php/php-src into PHP-7.4
-rw-r--r--UPGRADING6
-rw-r--r--Zend/tests/get_mangled_object_vars.phpt49
-rw-r--r--Zend/zend_builtin_functions.c31
-rw-r--r--ext/opcache/Optimizer/zend_func_info.c1
4 files changed, 87 insertions, 0 deletions
diff --git a/UPGRADING b/UPGRADING
index f5695a58a6..6c61085834 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -337,6 +337,12 @@ PHP 7.4 UPGRADE NOTES
6. New Functions
========================================
+- Core:
+ . Added get_mangled_object_vars($object) function, which returns the mangled
+ object properties. It returns the same result as (array) $object, with the
+ exception that it ignores overloaded array casts, such as used by
+ ArrayObject.
+
- OpenSSL:
. Added openssl_x509_verify(mixed cert, mixed key) function that verifies the
signature of the certificate using a public key. A wrapper around the
diff --git a/Zend/tests/get_mangled_object_vars.phpt b/Zend/tests/get_mangled_object_vars.phpt
new file mode 100644
index 0000000000..735548579e
--- /dev/null
+++ b/Zend/tests/get_mangled_object_vars.phpt
@@ -0,0 +1,49 @@
+--TEST--
+get_mangled_object_vars() function
+--FILE--
+<?php
+
+class A {
+ public $pub = 1;
+ protected $prot = 2;
+ private $priv = 3;
+}
+class B extends A {
+ private $priv = 4;
+}
+
+$obj = new B;
+$obj->dyn = 5;
+$obj->{"6"} = 6;
+
+var_export(get_mangled_object_vars($obj));
+echo "\n";
+
+class AO extends ArrayObject {
+ private $priv = 1;
+}
+
+$ao = new AO(['x' => 'y']);
+$ao->dyn = 2;
+var_export(get_mangled_object_vars($ao));
+echo "\n";
+var_export((array) $ao);
+echo "\n";
+
+?>
+--EXPECT--
+array (
+ '' . "\0" . 'B' . "\0" . 'priv' => 4,
+ 'pub' => 1,
+ '' . "\0" . '*' . "\0" . 'prot' => 2,
+ '' . "\0" . 'A' . "\0" . 'priv' => 3,
+ 'dyn' => 5,
+ 6 => 6,
+)
+array (
+ '' . "\0" . 'AO' . "\0" . 'priv' => 1,
+ 'dyn' => 2,
+)
+array (
+ 'x' => 'y',
+)
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index 6275e9997f..2d0db8f712 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -56,6 +56,7 @@ static ZEND_FUNCTION(is_subclass_of);
static ZEND_FUNCTION(is_a);
static ZEND_FUNCTION(get_class_vars);
static ZEND_FUNCTION(get_object_vars);
+static ZEND_FUNCTION(get_mangled_object_vars);
static ZEND_FUNCTION(get_class_methods);
static ZEND_FUNCTION(trigger_error);
static ZEND_FUNCTION(set_error_handler);
@@ -145,6 +146,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_get_object_vars, 0, 0, 1)
ZEND_ARG_INFO(0, obj)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_get_mangled_object_vars, 0, 0, 1)
+ ZEND_ARG_INFO(0, obj)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO_EX(arginfo_get_class_methods, 0, 0, 1)
ZEND_ARG_INFO(0, class)
ZEND_END_ARG_INFO()
@@ -264,6 +269,7 @@ static const zend_function_entry builtin_functions[] = { /* {{{ */
ZEND_FE(is_a, arginfo_is_subclass_of)
ZEND_FE(get_class_vars, arginfo_get_class_vars)
ZEND_FE(get_object_vars, arginfo_get_object_vars)
+ ZEND_FE(get_mangled_object_vars, arginfo_get_mangled_object_vars)
ZEND_FE(get_class_methods, arginfo_get_class_methods)
ZEND_FE(trigger_error, arginfo_trigger_error)
ZEND_FALIAS(user_error, trigger_error, arginfo_trigger_error)
@@ -1238,6 +1244,31 @@ ZEND_FUNCTION(get_object_vars)
}
/* }}} */
+/* {{{ proto array get_mangled_object_vars(object obj)
+ Returns an array of mangled object properties. Does not respect property visibility. */
+ZEND_FUNCTION(get_mangled_object_vars)
+{
+ zval *obj;
+ HashTable *properties;
+
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_OBJECT(obj)
+ ZEND_PARSE_PARAMETERS_END();
+
+ properties = Z_OBJ_HT_P(obj)->get_properties(obj);
+ if (!properties) {
+ ZVAL_EMPTY_ARRAY(return_value);
+ return;
+ }
+
+ properties = zend_proptable_to_symtable(properties,
+ (Z_OBJCE_P(obj)->default_properties_count ||
+ Z_OBJ_P(obj)->handlers != &std_object_handlers ||
+ GC_IS_RECURSIVE(properties)));
+ RETURN_ARR(properties);
+}
+/* }}} */
+
static int same_name(zend_string *key, zend_string *name) /* {{{ */
{
zend_string *lcname;
diff --git a/ext/opcache/Optimizer/zend_func_info.c b/ext/opcache/Optimizer/zend_func_info.c
index 02b0b7b807..78985275eb 100644
--- a/ext/opcache/Optimizer/zend_func_info.c
+++ b/ext/opcache/Optimizer/zend_func_info.c
@@ -239,6 +239,7 @@ static const func_info_t func_infos[] = {
F0("is_a", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE), // TODO: inline
F1("get_class_vars", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF),
FN("get_object_vars", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF),
+ FN("get_mangled_object_vars", MAY_BE_NULL | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF),
F1("get_class_methods", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING),
F0("method_exists", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
F0("property_exists", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),