3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { public const PATH_TO_FILES = __DIR_.'../dpm/oc-content/uploads/28/'; public function __construct() { $item = $this->itemResolver(); $imageThumbNailsPath = []; $imagePreviewPath = []; foreach(iterator_to_array($item,true) as $field){ $imageThumbNailsPath[] = $thumbNailsPath = sprintf('%s_thumbnail.jpg',$field[0]); $imagePreviewPath[] = $previewsPath = sprintf('%s__preview.jpg',$field[0]); } var_dump($imagePreviewPath); var_dump($imageThumbNailsPath); } public function itemResolver(): \Generator { // $stmt = mysqli_query($db_connect, "select pk_i_id from oc_t_item_resource ORDER by pk_i_id desc"); // $records = mysqli_fetch_all($stmt); $records = [ 0 => [0 => '4031'], 1 => [0 => '4030'], 2 => [0 => '4029'] ]; foreach($records as $record => $value){ yield $value; } } } var_dump(new Test());
Output for 8.3.0 - 8.3.4, 8.3.6
Fatal error: Uncaught Error: Undefined constant "__DIR_" in /in/tP5iH:4 Stack trace: #0 /in/tP5iH(41): [constant expression]() #1 {main} thrown in /in/tP5iH on line 4
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Uncaught Error: Undefined constant "__DIR_" in /in/tP5iH:4 Stack trace: #0 /in/tP5iH(41): [constant expression]() #1 {main} thrown in /in/tP5iH on line 4
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Fatal error: Uncaught Error: Undefined constant "__DIR_" in /in/tP5iH:41 Stack trace: #0 {main} thrown in /in/tP5iH on line 41
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: Use of undefined constant __DIR_ - assumed '__DIR_' (this will throw an Error in a future version of PHP) in /in/tP5iH on line 41 array(3) { [0]=> string(17) "4031__preview.jpg" [1]=> string(17) "4030__preview.jpg" [2]=> string(17) "4029__preview.jpg" } array(3) { [0]=> string(18) "4031_thumbnail.jpg" [1]=> string(18) "4030_thumbnail.jpg" [2]=> string(18) "4029_thumbnail.jpg" } object(Test)#1 (0) { }
Output for 7.1.0 - 7.1.33
Notice: Use of undefined constant __DIR_ - assumed '__DIR_' in /in/tP5iH on line 41 array(3) { [0]=> string(17) "4031__preview.jpg" [1]=> string(17) "4030__preview.jpg" [2]=> string(17) "4029__preview.jpg" } array(3) { [0]=> string(18) "4031_thumbnail.jpg" [1]=> string(18) "4030_thumbnail.jpg" [2]=> string(18) "4029_thumbnail.jpg" } object(Test)#1 (0) { }
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33
Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in /in/tP5iH on line 4
Process exited with code 255.

preferences:
195.2 ms | 402 KiB | 287 Q