Re: [PHP-DEV] Unified ReflectionType methods

2021-10-02 Thread Sebastian Bergmann

Am 02.10.2021 um 16:37 schrieb tyson andre:

`ReflectionType->allowsValue(mixed $value, bool $strict = true): bool`


Not having to implement and maintain that functionality in userland would 
be brilliant and much appreciated. Right now we have 
https://github.com/sebastianbergmann/type for this for use cases related 
to test doubles in PHPUnit.


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php



[PHP-DEV] [RFC] Allow null as standalone type

2021-10-02 Thread G. P. B.
Hello internals,

I'm proposing a new RFC to make 'null' usable as a standalone type.

RFC: https://wiki.php.net/rfc/null-standalone-type
GitHub PR: https://github.com/php/php-src/pull/7546

Best regards,

George P. Banyard


Re: [PHP-DEV] Unified ReflectionType methods

2021-10-02 Thread tyson andre
Hi Andreas,

> Hello list,
> I would like to propose new methods for ReflectionType, that would
> allow treating ReflectionNamedType and ReflectionUnionType in a
> unified way.
> This would eliminate the need for if (.. instanceof) in many use cases.
> 
> Some details can still be discussed, e.g. whether 'null' should be
> included in builtin type names, whether there should be a canonical
> ordering of type names, whether we should use class names as array
> keys, etc.
> ... 
> What do you think?

Relatedly, I also had different ideas lately about new methods for 
ReflectionType, though of a different form.

1. To simplify code that would check `instanceof` for all current and future 
types such as `never` and `mixed` and intersection types
`ReflectionType->allowsValue(mixed $value, bool $strict = true): bool`

   Maybe also `allowsClass(string $className, bool $strict = true): bool` to 
avoid needing to instantiate values (weak casting allows Stringable->string).
2. To simplify code generation, e.g. in mocking libraries for unit testing: 
`ReflectionType->toFullyQualifiedString(): string` (e.g. `\A|\B`) (may need to 
throw ReflectionType for types that can't be resolved, e.g. `parent` in 
reflection of traits, keep `static` as is)

(The raw output of `__toString()` isn't prefixed with `\` (e.g. `A`) and 
can't be used in namespaces

The fact that both intersection and union types (and possibility of union types 
of full intersection types)
make it hard for me to believe that getBuiltinTypes and getBuiltinClasses would 
be used correctly when used.

Thanks,
Tyson
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php