3v4l.org

run code in 500+ PHP versions simultaneously
<?php $a = [null]; echo 'null, valid cast: ' . array_product($a) . "\n\n"; $a = [false]; echo 'false, valid cast: ' . array_product($a) . "\n\n"; $a = [true]; echo 'true, valid cast: ' . array_product($a) . "\n\n"; $a = ['']; echo 'empty string, invalid cast: ' . array_product($a) . "\n\n"; $a = ['42.5']; echo 'string of a float, valid cast: ' . array_product($a) . "\n\n"; $a = ['42,5']; echo 'string of comma-separated float, valid cast but not desirable (discards trailing chars): ' . array_product($a) . "\n\n"; $a = ['42a']; echo 'string of int with trailing alpha char, valid cast but not desirable (discards trailing chars): ' . array_product($a) . "\n\n"; $a = ['a42']; echo 'string of int with leading alpha char, invalid cast: ' . array_product($a) . "\n\n"; $a = [[]]; echo 'array, invalid cast: ' . array_product($a) . "\n\n"; $a = [new stdClass()]; echo 'class that does not auto-cast, invalid cast: ' . array_product($a) . "\n\n"; $a = [gmp_init(42)]; echo 'gmp, valid cast: ' . array_product($a) . "\n\n";
Output for 8.5.1 - 8.5.3
null, valid cast: 0 false, valid cast: 0 true, valid cast: 1 Warning: array_product(): Multiplication is not supported on type string in /in/KdkVP on line 13 empty string, invalid cast: 0 string of a float, valid cast: 42.5 Warning: A non-numeric value encountered in /in/KdkVP on line 19 string of comma-separated float, valid cast but not desirable (discards trailing chars): 42 Warning: A non-numeric value encountered in /in/KdkVP on line 22 string of int with trailing alpha char, valid cast but not desirable (discards trailing chars): 42 Warning: array_product(): Multiplication is not supported on type string in /in/KdkVP on line 25 string of int with leading alpha char, invalid cast: 0 Warning: array_product(): Multiplication is not supported on type array in /in/KdkVP on line 28 array, invalid cast: 1 Warning: array_product(): Multiplication is not supported on type stdClass in /in/KdkVP on line 31 class that does not auto-cast, invalid cast: 1 Fatal error: Uncaught Error: Call to undefined function gmp_init() in /in/KdkVP:33 Stack trace: #0 {main} thrown in /in/KdkVP on line 33
Process exited with code 255.
Output for 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0
null, valid cast: 0 false, valid cast: 0 true, valid cast: 1 Warning: array_product(): Multiplication is not supported on type string in /in/KdkVP on line 13 empty string, invalid cast: 0 string of a float, valid cast: 42.5 Warning: A non-numeric value encountered in /in/KdkVP on line 19 string of comma-separated float, valid cast but not desirable (discards trailing chars): 42 Warning: A non-numeric value encountered in /in/KdkVP on line 22 string of int with trailing alpha char, valid cast but not desirable (discards trailing chars): 42 Warning: array_product(): Multiplication is not supported on type string in /in/KdkVP on line 25 string of int with leading alpha char, invalid cast: 0 Warning: array_product(): Multiplication is not supported on type array in /in/KdkVP on line 28 array, invalid cast: 1 Warning: array_product(): Multiplication is not supported on type stdClass in /in/KdkVP on line 31 class that does not auto-cast, invalid cast: 1 gmp, valid cast: 42
Output for 8.1.34, 8.2.0 - 8.2.30
null, valid cast: 0 false, valid cast: 0 true, valid cast: 1 empty string, invalid cast: 0 string of a float, valid cast: 42.5 string of comma-separated float, valid cast but not desirable (discards trailing chars): 42 string of int with trailing alpha char, valid cast but not desirable (discards trailing chars): 42 string of int with leading alpha char, invalid cast: 0 array, invalid cast: 1 class that does not auto-cast, invalid cast: 1 gmp, valid cast: 1

preferences:
51.89 ms | 903 KiB | 4 Q