3v4l.org

run code in 300+ PHP versions simultaneously
<?php $mnem=new mnemClass(); class mnemClass { public $mnemMap; public $mnemJux; public $cleanJux; public function __construct () { if(!is_dir($_SERVER["DOCUMENT_ROOT"]."/../cache/")) {mkdir($_SERVER["DOCUMENT_ROOT"]."/../cache/",0777,true);} $this->genPub(); $mnemMap = json_decode(file_get_contents($_SERVER["DOCUMENT_ROOT"]."/basrip dictionary/settings/reps.json"),true, 512, JSON_THROW_ON_ERROR)["mnemMap"]; $numMap = json_decode(file_get_contents($_SERVER["DOCUMENT_ROOT"]."/basrip dictionary/settings/reps.json"),true, 512, JSON_THROW_ON_ERROR)["numMap"]; foreach ( $mnemMap as $key => $value ) { $this->mnemJux[' '.$key.' ']=$value; } } public function seed_once($seed) { if(substr($seed,0,strlen("http://".$_SERVER["HTTP_HOST"]."/"))=="http://".$_SERVER["HTTP_HOST"]."/") { $seed = substr($seed,strlen("http://".$_SERVER["HTTP_HOST"]."/")); } $cachePath=$_SERVER["DOCUMENT_ROOT"]."/../cache/"; $seedPath=$_SERVER["DOCUMENT_ROOT"]."/"; // Get the filename from the path $file = basename($seed); // Get just the path $path = dirname($seed)."/"; if(substr($path,-strlen("/public/"))=="/public/") { $path.="pub/"; $cachePath.="pub/"; } var_dump(["path"=>$path,"file"=>$file]); if(!is_dir(dirname($cachePath))) {mkdir(dirname($cachePath)."/",0777,true);} if(is_file($seedPath.$file)) { var_dump(["copy",$path.$file,$cachePath.$file]); copy($seedPath.$file,$cachePath.$file); $buffer = file_get_contents($cachePath.$file); // $buffer=$this->fileGet($buffer); $buffer=$this->bufferSwap($buffer); // global injection $pattern='/function [^{]+\{[^{}]/mi'; if(preg_match_all($pattern,$buffer,$matches,PREG_SET_ORDER)>0) { foreach( $matches as $match) { $buffer=str_replace ( $match[0],$match[0]."\r\n\t\tglobal \$mnem;\r\n",$buffer); } } // Define the pattern for matching include statements $pattern = '/include(?<once>_once|)\s*\(($<file>[^;]+)\);/mi'; // Swap out inclusions in buffer if(preg_match_all ( $pattern, $buffer, $matches, PREG_SET_ORDER)>0) { foreach($matches as $match) { if($match["file"]==$_SERVER["DOCUMENT_ROOT"]."/Classes/mnemClass.php") {continue 1;} if(substr($match["file"],0,strlen("\$_SERVER[\"DOCUMENT_ROOT\"]"))=="\$_SERVER[\"DOCUMENT_ROOT\"]") { $match["file"]=str_replace("\$_SERVER[\"DOCUMENT_ROOT\"]",$_SERVER["DOCUMENT_ROOT"],$match["file"]); } $match["file"] = str_replace("\"","",$match["file"]); str_replace ( $match[0],"include".$match["once"]."(".$match["file"].");",$buffer); } } $buffer = file_get_contents($cachePath.$file); $buffer = $this->bufferSwap($buffer); file_put_contents($cachePath.$file,$buffer); // include_once ($_SERVER["DOCUMENT_ROOT"]."/../cache/".$path.$file); } return $cachePath.$file; } function fileGet($buffer="") { $pattern = '/^"(?<proto>(https?|ftp):\/\/)(?<addy>[^\s\/$.?#].[^\s]*)"$/mi'; if(preg_match_all($pattern,$buffer,$matches,PREG_SET_ORDER)>0) { foreach($matches as $match) { // Check if the substring is at the beginning of the string if (strpos($match[0], "http://".$_SERVER["HTTP_HOST"]."/pub/") === 0) { // Remove the substring from the beginning of the string $buffer = str_replace($match[0],"http://".$_SERVER["HTTP_HOST"]."/pub/".$match[0], $buffer); } } } return $buffer; } function cleanMap() { return [ "EMPTY"=>'', "CRLF"=>'\r\n', "CR"=>'\r', "LF"=>'\n', "HTAB"=>'\t', "TAB"=>'\t', "SP"=>' ', "COMMA"=>',', "QUOT"=>'"', "SEMI"=>';', "VARSEP"=>'::', "COLON"=>':', "ESC"=>'' ]; } public function bufferSwap($buffer) { $mnemMap = json_decode(file_get_contents($_SERVER["DOCUMENT_ROOT"]."/basrip dictionary/settings/reps.json"),true, 512, JSON_THROW_ON_ERROR)["mnemMap"]; $numMap = json_decode(file_get_contents($_SERVER["DOCUMENT_ROOT"]."/basrip dictionary/settings/reps.json"),true, 512, JSON_THROW_ON_ERROR)["numMap"]; $cleanMap=$this->cleanMap(); foreach ( $cleanMap as $key => $value ) { $cleanJux['EQ '.$key]='EQ "'.$value.'"'; } foreach ( $mnemMap as $key => $value ) { $mnemJux[' '.$key.' ']=$value; } foreach ( $numMap as $key => $value ) { $numJux[$key]=$value; } // Swap out special chars in buffer $buffer = str_replace ( array_keys ( $cleanJux ), array_values ( $cleanJux ), $buffer ); // Swap out mnemonics in buffer $buffer = str_replace ( array_keys ( $mnemJux ), array_values ( $mnemJux ), $buffer ); // Swap out numerics in buffer $buffer = str_replace ( array_keys ( $numJux ), array_values ( $numJux ), $buffer ); $buffer=str_replace("\r\n\r\n\r\n","\r\n\r\n",$buffer); return $buffer; } public function genPub() { if(!is_dir($_SERVER["DOCUMENT_ROOT"]."/../cache/pub/")) {mkdir($_SERVER["DOCUMENT_ROOT"]."/../cache/pub/",0777,true);} $files = array_map(fn($file) => basename($file, ".php").".php", glob($_SERVER["DOCUMENT_ROOT"]."/pub/*.php")); foreach($files as $file) { $buffer = file_get_contents($_SERVER["DOCUMENT_ROOT"]."/pub/".$file); $buffer = $this->bufferSwap($buffer); $buffer = $this->bufferHeader($buffer,"/pub/",$file); $buffer = file_put_contents($_SERVER["DOCUMENT_ROOT"]."/../cache/".$file,$buffer); } } public function bufferHeader($buffer,$path="",$file="") { $buffer = str_replace("<?php","",$buffer); $buffer = str_replace("?>","",$buffer); $buffer = "\$mnem=new mnemClass();\r\n".$buffer; $buffer = "include_once(\"" .$_SERVER["DOCUMENT_ROOT"]."/../mnem/mnemClass.php\");\r\n".$buffer; $buffer = '<?php'."\r\n".'/* "'.$path.$file.'" Built: '.date(DATE_RFC2822).' */'."\r\n".$buffer; return $buffer; } function crawlAndSwap($sourceDir, $destinationDir) { // Create recursive iterators to traverse the directory tree $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($sourceDir, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $file) { if ($file->isFile() && $file->getExtension() === 'php') { $filePath = $file->getPathname(); // Read the contents of the PHP file $contents = file_get_contents($filePath); // Perform your content swapping here // Example: Replace "old content" with "new content" // $newContents = str_replace("old content", "new content", $contents); $newContents = $this->bufferSwap($contents); // Determine the destination path for the modified file $destinationPath = str_replace($sourceDir, $destinationDir, $filePath); // Ensure the destination directory exists $destinationFileDir = dirname($destinationPath); if (!is_dir($destinationFileDir)) { mkdir($destinationFileDir, 0777, true); } // Write the modified contents to the destination file file_put_contents($destinationPath, $newContents); } } } public function crawlSwap() { // Example usage $sourceDir = $_SERVER["DOCUMENT_ROOT"]."/"; $destinationDir = $_SERVER["DOCUMENT_ROOT"]."/../reversion/"; if(!is_dir($destinationDir)) {mkdir($destinationDir,0777,true);} $this->crawlAndSwap($sourceDir, $destinationDir); } }
Output for 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
Warning: is_dir(): open_basedir restriction in effect. File(/../cache/) is not within the allowed path(s): (/tmp:/in:/etc) in /in/XBXHu on line 13 Warning: mkdir(): open_basedir restriction in effect. File(/cache/) is not within the allowed path(s): (/tmp:/in:/etc) in /in/XBXHu on line 14 Warning: is_dir(): open_basedir restriction in effect. File(/../cache/pub/) is not within the allowed path(s): (/tmp:/in:/etc) in /in/XBXHu on line 190 Warning: mkdir(): open_basedir restriction in effect. File(/cache/pub/) is not within the allowed path(s): (/tmp:/in:/etc) in /in/XBXHu on line 191 Warning: file_get_contents(): open_basedir restriction in effect. File(/basrip dictionary/settings/reps.json) is not within the allowed path(s): (/tmp:/in:/etc) in /in/XBXHu on line 18 Warning: file_get_contents(/basrip dictionary/settings/reps.json): Failed to open stream: Operation not permitted in /in/XBXHu on line 18 Fatal error: Uncaught JsonException: Syntax error in /in/XBXHu:18 Stack trace: #0 /in/XBXHu(18): json_decode('', true, 512, 4194304) #1 /in/XBXHu(3): mnemClass->__construct() #2 {main} thrown in /in/XBXHu on line 18
Process exited with code 255.
Output for 8.1.0 - 8.1.28
Warning: is_dir(): open_basedir restriction in effect. File(/../cache/) is not within the allowed path(s): (/tmp:/in:/etc) in /in/XBXHu on line 13 Warning: mkdir(): open_basedir restriction in effect. File(/cache/) is not within the allowed path(s): (/tmp:/in:/etc) in /in/XBXHu on line 14 Warning: is_dir(): open_basedir restriction in effect. File(/../cache/pub/) is not within the allowed path(s): (/tmp:/in:/etc) in /in/XBXHu on line 190 Warning: mkdir(): open_basedir restriction in effect. File(/cache/pub/) is not within the allowed path(s): (/tmp:/in:/etc) in /in/XBXHu on line 191 Fatal error: Uncaught TypeError: array_map(): Argument #2 ($array) must be of type array, bool given in /in/XBXHu:193 Stack trace: #0 /in/XBXHu(193): array_map(Object(Closure), false) #1 /in/XBXHu(16): mnemClass->genPub() #2 /in/XBXHu(3): mnemClass->__construct() #3 {main} thrown in /in/XBXHu on line 193
Process exited with code 255.

preferences:
80.91 ms | 402 KiB | 62 Q