From e10967d1ee7cf3939ad13887fa44acb29dc3329a Mon Sep 17 00:00:00 2001 From: Mikhail Kornaukhov <66915223+mkornaukhov03@users.noreply.github.com> Date: Tue, 14 Jan 2025 12:12:02 +0300 Subject: [PATCH] Fix is_object() function for objects inside mixed (#1207) --- .../core/core-types/definition/mixed.inl | 2 +- runtime-common/core/runtime-core.h | 4 ++ .../mixed/non_primitive/017_is_object.php | 43 +++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/phpt/mixed/non_primitive/017_is_object.php diff --git a/runtime-common/core/core-types/definition/mixed.inl b/runtime-common/core/core-types/definition/mixed.inl index 81ad05012c..1e609350c7 100644 --- a/runtime-common/core/core-types/definition/mixed.inl +++ b/runtime-common/core/core-types/definition/mixed.inl @@ -24,7 +24,7 @@ void mixed::init_from(T &&v) { if (unlikely(!ptr_to_obj)) { php_error("Internal error. Trying to set invalid object to mixed"); } - type_ = type::OBJECT; + type_ = v.is_null() ? type::NUL : type::OBJECT; } else { auto type_and_value_ref = get_type_and_value_ptr(v); type_ = type_and_value_ref.first; diff --git a/runtime-common/core/runtime-core.h b/runtime-common/core/runtime-core.h index 08c0401bbb..22f3b91f63 100644 --- a/runtime-common/core/runtime-core.h +++ b/runtime-common/core/runtime-core.h @@ -1185,6 +1185,10 @@ bool f$is_object(const class_instance &v) { return !v.is_null(); } +template<> +inline bool f$is_object(const mixed &v) { + return v.is_object(); +} template bool f$is_integer(const T &v) { diff --git a/tests/phpt/mixed/non_primitive/017_is_object.php b/tests/phpt/mixed/non_primitive/017_is_object.php new file mode 100644 index 0000000000..1f0b30becb --- /dev/null +++ b/tests/phpt/mixed/non_primitive/017_is_object.php @@ -0,0 +1,43 @@ +@ok +