Merge pull request #4036 from dokuwiki/issue4033
[dokuwiki.git] / _test / vendor / symfony / polyfill-php80 / Php80.php
blob362dd1a9596dde63ee3005474875af806f461b0a
1 <?php
3 /*
4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Polyfill\Php80;
14 /**
15 * @author Ion Bazan <ion.bazan@gmail.com>
16 * @author Nico Oelgart <nicoswd@gmail.com>
17 * @author Nicolas Grekas <p@tchwork.com>
19 * @internal
21 final class Php80
23 public static function fdiv(float $dividend, float $divisor): float
25 return @($dividend / $divisor);
28 public static function get_debug_type($value): string
30 switch (true) {
31 case null === $value: return 'null';
32 case \is_bool($value): return 'bool';
33 case \is_string($value): return 'string';
34 case \is_array($value): return 'array';
35 case \is_int($value): return 'int';
36 case \is_float($value): return 'float';
37 case \is_object($value): break;
38 case $value instanceof \__PHP_Incomplete_Class: return '__PHP_Incomplete_Class';
39 default:
40 if (null === $type = @get_resource_type($value)) {
41 return 'unknown';
44 if ('Unknown' === $type) {
45 $type = 'closed';
48 return "resource ($type)";
51 $class = \get_class($value);
53 if (false === strpos($class, '@')) {
54 return $class;
57 return (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous';
60 public static function get_resource_id($res): int
62 if (!\is_resource($res) && null === @get_resource_type($res)) {
63 throw new \TypeError(sprintf('Argument 1 passed to get_resource_id() must be of the type resource, %s given', get_debug_type($res)));
66 return (int) $res;
69 public static function preg_last_error_msg(): string
71 switch (preg_last_error()) {
72 case \PREG_INTERNAL_ERROR:
73 return 'Internal error';
74 case \PREG_BAD_UTF8_ERROR:
75 return 'Malformed UTF-8 characters, possibly incorrectly encoded';
76 case \PREG_BAD_UTF8_OFFSET_ERROR:
77 return 'The offset did not correspond to the beginning of a valid UTF-8 code point';
78 case \PREG_BACKTRACK_LIMIT_ERROR:
79 return 'Backtrack limit exhausted';
80 case \PREG_RECURSION_LIMIT_ERROR:
81 return 'Recursion limit exhausted';
82 case \PREG_JIT_STACKLIMIT_ERROR:
83 return 'JIT stack limit exhausted';
84 case \PREG_NO_ERROR:
85 return 'No error';
86 default:
87 return 'Unknown error';
91 public static function str_contains(string $haystack, string $needle): bool
93 return '' === $needle || false !== strpos($haystack, $needle);
96 public static function str_starts_with(string $haystack, string $needle): bool
98 return 0 === strncmp($haystack, $needle, \strlen($needle));
101 public static function str_ends_with(string $haystack, string $needle): bool
103 if ('' === $needle || $needle === $haystack) {
104 return true;
107 if ('' === $haystack) {
108 return false;
111 $needleLength = \strlen($needle);
113 return $needleLength <= \strlen($haystack) && 0 === substr_compare($haystack, $needle, -$needleLength);