-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Open
Description
Description
The following code:
<?php
$reflection = new ReflectionClass(mysqli::class);
$props = [];
foreach ($reflection->getProperties() as $property) {
$props[] = $property->getName() . ' | readonly: ' . (int) $property->isReadOnly();
}
print_r($props);
Resulted in this output:
Array
(
[0] => affected_rows | readonly: 0
[1] => client_info | readonly: 0
[2] => client_version | readonly: 0
[3] => connect_errno | readonly: 0
[4] => connect_error | readonly: 0
[5] => errno | readonly: 0
[6] => error | readonly: 0
[7] => error_list | readonly: 0
[8] => field_count | readonly: 0
[9] => host_info | readonly: 0
[10] => info | readonly: 0
[11] => insert_id | readonly: 0
[12] => server_info | readonly: 0
[13] => server_version | readonly: 0
[14] => sqlstate | readonly: 0
[15] => protocol_version | readonly: 0
[16] => thread_id | readonly: 0
[17] => warning_count | readonly: 0
)
But I expected this output instead:
Array
(
[0] => affected_rows | readonly: 1
[1] => client_info | readonly: 1
[2] => client_version | readonly: 1
[3] => connect_errno | readonly: 1
[4] => connect_error | readonly: 1
[5] => errno | readonly: 1
[6] => error | readonly: 1
[7] => error_list | readonly: 1
[8] => field_count | readonly: 1
[9] => host_info | readonly: 1
[10] => info | readonly: 1
[11] => insert_id | readonly: 1
[12] => server_info | readonly: 1
[13] => server_version | readonly: 1
[14] => sqlstate | readonly: 1
[15] => protocol_version | readonly: 1
[16] => thread_id | readonly: 1
[17] => warning_count | readonly: 1
)
PHP Version
PHP 8.3.8
Operating System
No response
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
iluuu1994 commentedon Aug 9, 2024
This is not bug, because these properties are not really
readonly
.php-src/ext/mysqli/mysqli.stub.php
Lines 616 to 617 in 46ee0fb
The
@readonly
is only added for documentation purposes.mysqli
handles property writes through custom object handlers that predate thereadonly
keyword, and they have not been migrated over. We can treat this as a feature request though.nielsdos commentedon Aug 10, 2024
The way I see it is that it's more like a "get" hook without a "set" hook. Reason being that the extension can still change the value. So I think that
isReadOnly
should actually return false.RV7PR commentedon Aug 10, 2024
Well, internally that may be true but on the user side it's still readonly so I think it should return true
iluuu1994 commentedon Aug 10, 2024
Readonly currently also means that the value never changes. If the value can change then readonly is not the correct flag to use.
cmb69 commentedon Aug 23, 2024
So
ReflectionProperty::getHooks()
and friends should ideally be implemented; at least, gen_stubs.php (and PhD) should be improved to handle@property-read
annotations. Is there already someone working on this (or is it planned)?iluuu1994 commentedon Aug 23, 2024
It gets a bit worse, since we can have a missing
set
operation (from the users pov) through various mechanisms:readonly
.set
, but only when the property is virtual.set
really just throws an exception.private(set)
.Maybe we should have something like:
is{Readable,Writeable}(?string $fromScope = null)
. It's not completely clear whether the default should refer to the current scope, orprivate
scope (i.e. the one used for{get,set}Value()
.cmb69 commentedon Aug 23, 2024
Okay, than leave this ticket for Reflection improvements/fixes, and have #15553 regarding the stubs.
Implement ReflectionProperty::is{Readable,Writable}()