diff --git a/ext/stub/properties/staticprotectedproperties.zep.c b/ext/stub/properties/staticprotectedproperties.zep.c index a4504c79ff..f943280cae 100644 --- a/ext/stub/properties/staticprotectedproperties.zep.c +++ b/ext/stub/properties/staticprotectedproperties.zep.c @@ -14,6 +14,7 @@ #include "kernel/main.h" #include "kernel/object.h" #include "kernel/memory.h" +#include "kernel/operators.h" ZEPHIR_INIT_CLASS(Stub_Properties_StaticProtectedProperties) @@ -193,3 +194,26 @@ PHP_METHOD(Stub_Properties_StaticProtectedProperties, getSomeString) RETURN_CTORW(&_0); } +PHP_METHOD(Stub_Properties_StaticProtectedProperties, compareStaticNull) +{ + zval someNull, _0; + zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(&someNull); + ZVAL_UNDEF(&_0); + + + ZEPHIR_MM_GROW(); + + ZEPHIR_OBS_VAR(&_0); + zephir_read_static_property_ce(&_0, stub_properties_staticprotectedproperties_ce, SL("someNull"), PH_NOISY_CC); + ZEPHIR_CPY_WRT(&someNull, &_0); + if (Z_TYPE_P(&someNull) == IS_NULL) { + ZEPHIR_INIT_NVAR(&someNull); + ZVAL_BOOL(&someNull, 1); + RETURN_CCTOR(&someNull); + } + RETURN_CCTOR(&someNull); +} + diff --git a/ext/stub/properties/staticprotectedproperties.zep.h b/ext/stub/properties/staticprotectedproperties.zep.h index 4007af9a35..05205678d4 100644 --- a/ext/stub/properties/staticprotectedproperties.zep.h +++ b/ext/stub/properties/staticprotectedproperties.zep.h @@ -13,6 +13,7 @@ PHP_METHOD(Stub_Properties_StaticProtectedProperties, getSomeTrue); PHP_METHOD(Stub_Properties_StaticProtectedProperties, getSomeInteger); PHP_METHOD(Stub_Properties_StaticProtectedProperties, getSomeDouble); PHP_METHOD(Stub_Properties_StaticProtectedProperties, getSomeString); +PHP_METHOD(Stub_Properties_StaticProtectedProperties, compareStaticNull); ZEND_BEGIN_ARG_INFO_EX(arginfo_stub_properties_staticprotectedproperties_setsomevar, 0, 0, 1) ZEND_ARG_INFO(0, someVar) @@ -46,6 +47,9 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_stub_properties_staticprotectedproperties_getsomestring, 0, 0, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stub_properties_staticprotectedproperties_comparestaticnull, 0, 0, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + ZEPHIR_INIT_FUNCS(stub_properties_staticprotectedproperties_method_entry) { PHP_ME(Stub_Properties_StaticProtectedProperties, setSomeVar, arginfo_stub_properties_staticprotectedproperties_setsomevar, ZEND_ACC_PUBLIC) #if PHP_VERSION_ID >= 80000 @@ -89,5 +93,6 @@ ZEPHIR_INIT_FUNCS(stub_properties_staticprotectedproperties_method_entry) { #else PHP_ME(Stub_Properties_StaticProtectedProperties, getSomeString, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) #endif + PHP_ME(Stub_Properties_StaticProtectedProperties, compareStaticNull, arginfo_stub_properties_staticprotectedproperties_comparestaticnull, ZEND_ACC_PUBLIC) PHP_FE_END }; diff --git a/stub/constantsparent.zep b/stub/constantsparent.zep index 072fcad095..52239ef0b4 100644 --- a/stub/constantsparent.zep +++ b/stub/constantsparent.zep @@ -3,7 +3,6 @@ namespace Stub; class ConstantsParent { - const P1 = null; const P2 = false; @@ -15,5 +14,4 @@ class ConstantsParent const P5 = 10.25; const P6 = "test"; - } diff --git a/stub/properties/staticprotectedproperties.zep b/stub/properties/staticprotectedproperties.zep index d0fdc9ac03..ab4bf8c8ee 100644 --- a/stub/properties/staticprotectedproperties.zep +++ b/stub/properties/staticprotectedproperties.zep @@ -3,7 +3,6 @@ namespace Stub\Properties; class StaticProtectedProperties { - /** * This is a protected property with no initial value */ @@ -81,4 +80,20 @@ class StaticProtectedProperties return self::someString; } + /** + * @issue https://github.com/zephir-lang/zephir/issues/1536 + */ + public function compareStaticNull() -> bool + { + var someNull; + + let someNull = self::someNull; + + if someNull === null { + let someNull = true; + return someNull; + } + + return someNull; + } } diff --git a/tests/Extension/Properties/StaticPropertyArrayTest.php b/tests/Extension/Properties/StaticPropertyArrayTest.php index b2cce1930d..c5255ee231 100644 --- a/tests/Extension/Properties/StaticPropertyArrayTest.php +++ b/tests/Extension/Properties/StaticPropertyArrayTest.php @@ -1,7 +1,5 @@ + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Extension\Properties; + +use PHPUnit\Framework\TestCase; +use Stub\Properties\StaticProtectedProperties; + +/** + * @issue https://github.com/zephir-lang/zephir/issues/1536 + */ +final class StaticProtectedPropertiesTest extends TestCase +{ + public function testCompareStaticNullOnBuiltIn(): void + { + $class = new StaticProtectedProperties(); + $this->assertTrue($class->compareStaticNull()); + } + + public function testCompareStaticNullOnExtending(): void + { + $spp = new \TestStaticProtectedProperties(); + $this->assertTrue($spp->compareStaticNull()); + } +} diff --git a/tests/fixtures/mocks/TestScopePhpMagicExtending.php b/tests/fixtures/mocks/TestScopePhpMagicExtending.php index 600419777e..21f72082c0 100644 --- a/tests/fixtures/mocks/TestScopePhpMagicExtending.php +++ b/tests/fixtures/mocks/TestScopePhpMagicExtending.php @@ -8,6 +8,7 @@ * For the full copyright and license information, please view * the LICENSE file that was distributed with this source code. */ + class TestScopePhpMagicExtending extends TestScopePhpMagic { private $privateProperty2 = 'private2'; diff --git a/tests/fixtures/mocks/TestStaticProtectedProperties.php b/tests/fixtures/mocks/TestStaticProtectedProperties.php new file mode 100644 index 0000000000..05c37616af --- /dev/null +++ b/tests/fixtures/mocks/TestStaticProtectedProperties.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +use Stub\Properties\StaticProtectedProperties; + +/** + * @issue https://github.com/zephir-lang/zephir/issues/1536 + */ +class TestStaticProtectedProperties extends StaticProtectedProperties +{ +}