Skip to content

Commit c91ea94

Browse files
committed
Use typed proprety for Transliterator::$id
This is a read-only property for which Transliterator internally assigns a string value. Also clean up the code handling this property a bit.
1 parent 2ccf630 commit c91ea94

File tree

3 files changed

+11
-31
lines changed

3 files changed

+11
-31
lines changed

ext/intl/transliterator/transliterator.stub.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
class Transliterator
66
{
7-
/** @var string|null */
8-
public $id;
7+
public string $id;
98

109
final private function __construct() {}
1110

ext/intl/transliterator/transliterator_arginfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 2ea0ba060d9b3cb9a7e8ca4a5932c755bf8df7d0 */
2+
* Stub hash: c34871965e0d58bb15beda1787b7cdd0754bb28f */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Transliterator___construct, 0, 0, 0)
55
ZEND_END_ARG_INFO()
@@ -59,9 +59,9 @@ zend_class_entry *register_class_Transliterator()
5959
class_entry = zend_register_internal_class_ex(&ce, NULL);
6060

6161
zval property_id_default_value;
62-
ZVAL_NULL(&property_id_default_value);
62+
ZVAL_UNDEF(&property_id_default_value);
6363
zend_string *property_id_name = zend_string_init("id", sizeof("id") - 1, 1);
64-
zend_declare_property_ex(class_entry, property_id_name, &property_id_default_value, ZEND_ACC_PUBLIC, NULL);
64+
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));
6565
zend_string_release(property_id_name);
6666

6767
return class_entry;

ext/intl/transliterator/transliterator_class.c

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,10 @@ static zend_object *Transliterator_clone_obj( zend_object *object )
189189
/* {{{ get_property_ptr_ptr handler */
190190
static zval *Transliterator_get_property_ptr_ptr( zend_object *object, zend_string *name, int type, void **cache_slot )
191191
{
192-
zval *retval;
193-
194-
if(zend_binary_strcmp( "id", sizeof( "id" ) - 1,
195-
ZSTR_VAL( name ), ZSTR_LEN( name ) ) == 0 )
196-
{
197-
retval = NULL; /* fallback to read_property */
192+
if (zend_string_equals_literal(name, "id")) {
193+
return NULL; /* fallback to read_property */
198194
}
199-
else
200-
{
201-
retval = zend_std_get_property_ptr_ptr( object, name, type, cache_slot );
202-
}
203-
204-
return retval;
195+
return zend_std_get_property_ptr_ptr( object, name, type, cache_slot );
205196
}
206197
/* }}} */
207198

@@ -210,15 +201,10 @@ static zval *Transliterator_read_property( zend_object *object, zend_string *nam
210201
{
211202
zval *retval;
212203

213-
if( ( type != BP_VAR_R && type != BP_VAR_IS ) &&
214-
( zend_binary_strcmp( "id", sizeof( "id" ) - 1,
215-
ZSTR_VAL( name ), ZSTR_LEN( name ) ) == 0 ) )
216-
{
204+
if ((type != BP_VAR_R && type != BP_VAR_IS) && zend_string_equals_literal(name, "id")) {
217205
zend_throw_error(NULL, "Transliterator::$id is read-only");
218206
retval = &EG( uninitialized_zval );
219-
}
220-
else
221-
{
207+
} else {
222208
retval = zend_std_read_property( object, name, type, cache_slot, rv );
223209
}
224210

@@ -238,14 +224,9 @@ static zval *Transliterator_write_property( zend_object *object, zend_string *na
238224
} else {
239225
scope = zend_get_executed_scope();
240226
}
241-
if( ( scope != Transliterator_ce_ptr ) &&
242-
( zend_binary_strcmp( "id", sizeof( "id" ) - 1,
243-
ZSTR_VAL( name ), ZSTR_LEN( name ) ) == 0 ) )
244-
{
227+
if ((scope != Transliterator_ce_ptr) && zend_string_equals_literal(name, "id")) {
245228
zend_throw_error(NULL, "Transliterator::$id is read-only");
246-
}
247-
else
248-
{
229+
} else {
249230
value = zend_std_write_property( object, name, value, cache_slot );
250231
}
251232

0 commit comments

Comments
 (0)