]> granicus.if.org Git - php/commitdiff
Use typed proprety for Transliterator::$id
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 15 Feb 2021 11:25:55 +0000 (12:25 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 15 Feb 2021 11:27:25 +0000 (12:27 +0100)
This is a read-only property for which Transliterator internally
assigns a string value.

Also clean up the code handling this property a bit.

ext/intl/transliterator/transliterator.stub.php
ext/intl/transliterator/transliterator_arginfo.h
ext/intl/transliterator/transliterator_class.c

index c893e111f0eb63a36f6e02087dcc148f3847457b..e8e147ac8eab50316ff92fa2d978112d3febd99f 100644 (file)
@@ -4,8 +4,7 @@
 
 class Transliterator
 {
-    /** @var string|null */
-    public $id;
+    public string $id;
 
     final private function __construct() {}
 
index 0e5249493fab126e32c70e1d6b3f2729e29d62c0..1cf928b7b8c78e8a4aaae15b1a26af8524a80e73 100644 (file)
@@ -1,5 +1,5 @@
 /* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 2ea0ba060d9b3cb9a7e8ca4a5932c755bf8df7d0 */
+ * Stub hash: c34871965e0d58bb15beda1787b7cdd0754bb28f */
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Transliterator___construct, 0, 0, 0)
 ZEND_END_ARG_INFO()
@@ -59,9 +59,9 @@ zend_class_entry *register_class_Transliterator()
        class_entry = zend_register_internal_class_ex(&ce, NULL);
 
        zval property_id_default_value;
-       ZVAL_NULL(&property_id_default_value);
+       ZVAL_UNDEF(&property_id_default_value);
        zend_string *property_id_name = zend_string_init("id", sizeof("id") - 1, 1);
-       zend_declare_property_ex(class_entry, property_id_name, &property_id_default_value, ZEND_ACC_PUBLIC, NULL);
+       zend_declare_typed_property(class_entry, property_id_name, &property_id_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
        zend_string_release(property_id_name);
 
        return class_entry;
index 9959be91c198b83720a6fcd3b664b2c9720612f4..0ca4fda7557fb73a3d2f3ea5c0d16ba878d96b44 100644 (file)
@@ -189,19 +189,10 @@ err:
 /* {{{ get_property_ptr_ptr handler */
 static zval *Transliterator_get_property_ptr_ptr( zend_object *object, zend_string *name, int type, void **cache_slot )
 {
-       zval *retval;
-
-       if(zend_binary_strcmp( "id", sizeof( "id" ) - 1,
-               ZSTR_VAL( name ), ZSTR_LEN( name ) ) == 0 )
-       {
-               retval = NULL; /* fallback to read_property */
+       if (zend_string_equals_literal(name, "id")) {
+               return NULL; /* fallback to read_property */
        }
-       else
-       {
-               retval = zend_std_get_property_ptr_ptr( object, name, type, cache_slot );
-       }
-
-       return retval;
+       return zend_std_get_property_ptr_ptr( object, name, type, cache_slot );
 }
 /* }}} */
 
@@ -210,15 +201,10 @@ static zval *Transliterator_read_property( zend_object *object, zend_string *nam
 {
        zval *retval;
 
-       if( ( type != BP_VAR_R && type != BP_VAR_IS ) &&
-               ( zend_binary_strcmp( "id", sizeof( "id" ) - 1,
-               ZSTR_VAL( name ), ZSTR_LEN( name ) ) == 0 ) )
-       {
+       if ((type != BP_VAR_R && type != BP_VAR_IS) && zend_string_equals_literal(name, "id")) {
                zend_throw_error(NULL, "Transliterator::$id is read-only");
                retval = &EG( uninitialized_zval );
-       }
-       else
-       {
+       } else {
                retval = zend_std_read_property( object, name, type, cache_slot, rv );
        }
 
@@ -238,14 +224,9 @@ static zval *Transliterator_write_property( zend_object *object, zend_string *na
        } else {
                scope = zend_get_executed_scope();
        }
-       if( ( scope != Transliterator_ce_ptr ) &&
-               ( zend_binary_strcmp( "id", sizeof( "id" ) - 1,
-               ZSTR_VAL( name ), ZSTR_LEN( name ) ) == 0 ) )
-       {
+       if ((scope != Transliterator_ce_ptr) && zend_string_equals_literal(name, "id")) {
                zend_throw_error(NULL, "Transliterator::$id is read-only");
-       }
-       else
-       {
+       } else {
                value = zend_std_write_property( object, name, value, cache_slot );
        }