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){ $thumbNailsPath = sprintf('%s_thumbnail.jpg',$field); $previewsPath = sprintf('%s__preview.jpg',$field); } 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/8knp2:4 Stack trace: #0 /in/8knp2(41): [constant expression]() #1 {main} thrown in /in/8knp2 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/8knp2:4 Stack trace: #0 /in/8knp2(41): [constant expression]() #1 {main} thrown in /in/8knp2 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/8knp2:41 Stack trace: #0 {main} thrown in /in/8knp2 on line 41
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 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/8knp2 on line 41 Notice: Array to string conversion in /in/8knp2 on line 12 Notice: Array to string conversion in /in/8knp2 on line 13 Notice: Array to string conversion in /in/8knp2 on line 12 Notice: Array to string conversion in /in/8knp2 on line 13 Notice: Array to string conversion in /in/8knp2 on line 12 Notice: Array to string conversion in /in/8knp2 on line 13 array(0) { } array(0) { } object(Test)#1 (0) { }
Output for 7.3.32 - 7.3.33
Warning: Use of undefined constant __DIR_ - assumed '__DIR_' (this will throw an Error in a future version of PHP) in /in/8knp2 on line 41 array(0) { } array(0) { } object(Test)#1 (0) { }
Output for 7.1.0 - 7.1.25
Notice: Use of undefined constant __DIR_ - assumed '__DIR_' in /in/8knp2 on line 41 Notice: Array to string conversion in /in/8knp2 on line 12 Notice: Array to string conversion in /in/8knp2 on line 13 Notice: Array to string conversion in /in/8knp2 on line 12 Notice: Array to string conversion in /in/8knp2 on line 13 Notice: Array to string conversion in /in/8knp2 on line 12 Notice: Array to string conversion in /in/8knp2 on line 13 array(0) { } array(0) { } object(Test)#1 (0) { }
Output for 5.6.38
Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in /in/8knp2 on line 4
Process exited with code 255.

preferences:
175.16 ms | 401 KiB | 178 Q