rfc:get_debug_type
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:get_debug_type [2020/02/17 09:42] – marandall | rfc:get_debug_type [2020/08/01 23:41] (current) – RFC was implemented carusogabriel | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2020-02-15 | * Date: 2020-02-15 | ||
* Author: Mark Randall, marandall@php.net | * Author: Mark Randall, marandall@php.net | ||
- | * Status: | + | * Status: |
* First Published at: https:// | * First Published at: https:// | ||
Line 9: | Line 9: | ||
This RFC proposes to add a new function get_debug_type that will return the given type of a variable. | This RFC proposes to add a new function get_debug_type that will return the given type of a variable. | ||
- | This function would differ from gettype in that it would return native type names, e.g. " | + | This is to replace the following pattern, which may be used to generate debugging messages when dealing with types which cannot be handled by existing PHP runtime checking based on parameter types, such as those coming from an array. |
- | 0 => int | + | <code php> |
- | 0.1 => float | + | $bar = $arr[' |
- | true => bool | + | if (!($bar instanceof Foo)) { |
- | false => bool | + | // this shows the most simple of patterns, to get the real type an assoc array |
- | " | + | // must be present to convert long-form " |
- | [] => array | + | throw new TypeError(' |
- | null => null | + | } |
- | A class with name " | + | |
- | An anonymous class => class@anonymous | + | // would become |
- | A resource | + | if (!($bar instanceof Foo)) { |
- | A closed resource | + | throw new TypeError(' |
+ | } | ||
+ | |||
+ | $bar-> | ||
+ | </ | ||
+ | |||
+ | This function would differ from gettype in that it would return native type names, e.g. " | ||
+ | |||
+ | ^ Value ^ get_debug_type() ^ gettype() ^ | ||
+ | | 0 | int | integer | | ||
+ | | 0.1 | float | double | | ||
+ | | true | ||
+ | | false | bool | boolean | | ||
+ | | " | ||
+ | | [] | ||
+ | | null | ||
+ | | A class with name " | ||
+ | | An anonymous class | class@anonymous | ||
+ | | A resource | ||
+ | | A closed resource | ||
Line 31: | Line 50: | ||
PHP 8.0 | PHP 8.0 | ||
- | ===== Proposed | + | ===== Voting ===== |
- | Yes / no vote on adding the new function. | + | |
- | + | ||
- | Yes / no on resource names be resolved - Would appear as resource(resource_type). | + | |
- | (Optional) A vote on the name, if there is not a clear majority consensus during RFC discussion. | + | <doodle title=" |
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
rfc/get_debug_type.1581932523.txt.gz · Last modified: 2020/02/17 09:42 by marandall