On Fri, Nov 7, 2025, at 5:03 AM, Tim Düsterhus wrote:
> Hi
>
> Am 2025-11-06 00:24, schrieb Larry Garfield:
>> In other news, Ilija and I said a year ago that we'd take a swing at 
>> adding isReadable/isWriteable methods to ReflectionProperty.  Took a 
>> while, but here we are.  A strangely small RFC from us:
>> 
>> https://wiki.php.net/rfc/isreadable-iswriteable
>
> I dislike implicitly “scope-dependent” functions, since they effectively 
> act like magic. This probably makes it harder to understand for humans 
> and static analysis tools alike. I would therefore suggest making the 
> `$scope` parameter required. A user can just pass `static::class` 
> themselves and static analysis tools can use `class-string|null` instead 
> of `class-string|"static"|null` as their expected parameter type.

Given that the 90% or more case is likely to be "from my current context", 
making that the default seems the most ergonomic.  (The counter argument, I 
suppose, is that this is hardly going to be a super-common routine to call so 
ergonomics don't matter.)

stack-inspection isn't new.  `Closure::getCurrent()` is the most recent 
example, so we don't think it's especially problematic.

If there's a preference for avoiding magic strings, it would be easy enough to 
use an enum instead.  Something like:

enum CallerScope {
  case Caller;
  case Global;
}

function isReadable(string|CallerScope $scope = CallerScope::Caller, ?object 
$objecg = null) { ... }

`Caller` would still do the same stack inspection, but it makes the type more 
tightly controlled and eliminates a nullable.

> As for the magic method logic: I would suggest to ignore the presence of 
> __get() and __set(). This more closely aligns with the direction PHP 
> goes towards and is also easy to work around by checking with 
> `method_exists()` whether any such a method exists - the reverse is not 
> true.

thumbs-up.gif

--Larry Garfield

Reply via email to