-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #226 [Php80] Add get_debug_type() (nicolas-grekas)
This PR was merged into the 1.15-dev branch. Discussion ---------- [Php80] Add get_debug_type() Waiting for - [ ] php/php-src#5143 - [ ] https://wiki.php.net/rfc/get_debug_type - [x] php/php-src#5153 Commits ------- 61168ea [Php80] Add get_debug_type()
- Loading branch information
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
/** | ||
* @author Ion Bazan <[email protected]> | ||
* @author Nico Oelgart <[email protected]> | ||
* @author Nicolas Grekas <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
|
@@ -24,6 +25,38 @@ public static function fdiv(float $dividend, float $divisor): float | |
return @($dividend / $divisor); | ||
} | ||
|
||
public static function get_debug_type($value): string | ||
{ | ||
switch (true) { | ||
case null === $value: return 'null'; | ||
case \is_bool($value): return 'bool'; | ||
case \is_string($value): return 'string'; | ||
case \is_array($value): return 'array'; | ||
case \is_int($value): return 'int'; | ||
case \is_float($value): return 'float'; | ||
case \is_object($value): break; | ||
case $value instanceof \__PHP_Incomplete_Class: return '__PHP_Incomplete_Class'; | ||
default: | ||
if (null === $type = @get_resource_type($value)) { | ||
return 'unknown'; | ||
} | ||
|
||
if ('Unknown' === $type) { | ||
$type = 'closed'; | ||
} | ||
|
||
return "resource ($type)"; | ||
} | ||
|
||
$class = \get_class($value); | ||
|
||
if (false === strpos($class, '@')) { | ||
return $class; | ||
} | ||
|
||
return (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous'; | ||
} | ||
|
||
public static function preg_last_error_msg(): string | ||
{ | ||
switch (preg_last_error()) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters