Last active
April 30, 2020 11:55
-
-
Save dd32/ef8a915856e9e985475d0cb7940d541e to your computer and use it in GitHub Desktop.
Example of altering the Symfony PHP8.0 polyfill to be parsable under PHP 5.6
This file contains hidden or 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
diff --git a/src/Php80/Php80.php b/src/Php80/Php80.php | |
index ba74359..bc2533c 100644 | |
--- a/src/Php80/Php80.php | |
+++ b/src/Php80/Php80.php | |
@@ -20,12 +20,12 @@ namespace Symfony\Polyfill\Php80; | |
*/ | |
final class Php80 | |
{ | |
- public static function fdiv(float $dividend, float $divisor): float | |
+ public static function fdiv(float $dividend, float $divisor) //: float | |
{ | |
return @($dividend / $divisor); | |
} | |
- public static function get_debug_type($value): string | |
+ public static function get_debug_type($value) //: string | |
{ | |
switch (true) { | |
case null === $value: return 'null'; | |
@@ -57,7 +57,7 @@ final class Php80 | |
return (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous'; | |
} | |
- public static function preg_last_error_msg(): string | |
+ public static function preg_last_error_msg() //: string | |
{ | |
switch (preg_last_error()) { | |
case PREG_INTERNAL_ERROR: | |
@@ -79,17 +79,17 @@ final class Php80 | |
} | |
} | |
- public static function str_contains(string $haystack, string $needle): bool | |
+ public static function str_contains(string $haystack, string $needle) //: bool | |
{ | |
return '' === $needle || false !== strpos($haystack, $needle); | |
} | |
- public static function str_starts_with(string $haystack, string $needle): bool | |
+ public static function str_starts_with(string $haystack, string $needle) //: bool | |
{ | |
return 0 === \strncmp($haystack, $needle, \strlen($needle)); | |
} | |
- public static function str_ends_with(string $haystack, string $needle): bool | |
+ public static function str_ends_with(string $haystack, string $needle) //: bool | |
{ | |
return '' === $needle || $needle === \substr($haystack, -\strlen($needle)); | |
} | |
diff --git a/src/Php80/bootstrap.php b/src/Php80/bootstrap.php | |
index dc2aaa4..b8366a7 100644 | |
--- a/src/Php80/bootstrap.php | |
+++ b/src/Php80/bootstrap.php | |
@@ -13,23 +13,23 @@ use Symfony\Polyfill\Php80 as p; | |
if (PHP_VERSION_ID < 80000) { | |
if (!function_exists('fdiv')) { | |
- function fdiv(float $dividend, float $divisor): float { return p\Php80::fdiv($dividend, $divisor); } | |
+ function fdiv(float $dividend, float $divisor) /*: float */ { return p\Php80::fdiv($dividend, $divisor); } | |
} | |
if (!function_exists('preg_last_error_msg')) { | |
- function preg_last_error_msg(): string { return p\Php80::preg_last_error_msg(); } | |
+ function preg_last_error_msg() /*: string */ { return p\Php80::preg_last_error_msg(); } | |
} | |
if (!function_exists('str_contains')) { | |
- function str_contains(string $haystack, string $needle): bool { return p\Php80::str_contains($haystack, $needle); } | |
+ function str_contains(string $haystack, string $needle) /*: bool */ { return p\Php80::str_contains($haystack, $needle); } | |
} | |
if (!function_exists('str_starts_with')) { | |
- function str_starts_with(string $haystack, string $needle): bool { return p\Php80::str_starts_with($haystack, $needle); } | |
+ function str_starts_with(string $haystack, string $needle) /*: bool */ { return p\Php80::str_starts_with($haystack, $needle); } | |
} | |
if (!function_exists('str_ends_with')) { | |
- function str_ends_with(string $haystack, string $needle): bool { return p\Php80::str_ends_with($haystack, $needle); } | |
+ function str_ends_with(string $haystack, string $needle) /*: bool */ { return p\Php80::str_ends_with($haystack, $needle); } | |
} | |
if (!defined('FILTER_VALIDATE_BOOL') && defined('FILTER_VALIDATE_BOOLEAN')) { | |
@@ -37,6 +37,6 @@ if (PHP_VERSION_ID < 80000) { | |
} | |
if (!function_exists('get_debug_type')) { | |
- function get_debug_type($value): string { return p\Php80::get_debug_type($value); } | |
+ function get_debug_type($value) /*: string */ { return p\Php80::get_debug_type($value); } | |
} | |
} | |
diff --git a/src/bootstrap.php b/src/bootstrap.php | |
index 6d92ed0..4e6519e 100644 | |
--- a/src/bootstrap.php | |
+++ b/src/bootstrap.php | |
@@ -9,6 +9,6 @@ | |
* file that was distributed with this source code. | |
*/ | |
-if (PHP_VERSION_ID < 80000 && PHP_VERSION_ID >= 70000) { | |
+if (PHP_VERSION_ID < 80000 /* && PHP_VERSION_ID >= 70000 */ ) { | |
require __DIR__.'/Php80/bootstrap.php'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment