3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = '$file%s = $entity->getForm%s(); if ($file%s) { $filename%s = uniqid() . \'.\' . $file%s->getClientOriginalExtension(); $this->filesystem->write($filename%s, file_get_contents($file%s->getPathname())); $entity->set%s(\'/imgs/upload/service/\' . $filename%s); }'; $elements = array( '1' => 'Photo', '2' => 'Icon', '3' => 'TopPhoto', '4' => 'DescriptionPhoto', '5' => 'BenefitPhoto', '6' => 'IndicationPhoto', '7' => 'PreparationPhoto', ); foreach ($elements as $key => $element) { echo sprintf($string, $key, $element, $key, $key, $key, $key, $key, $element, $key)."\n"."\n"; }
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
$file1 = $entity->getFormPhoto(); if ($file1) { $filename1 = uniqid() . '.' . $file1->getClientOriginalExtension(); $this->filesystem->write($filename1, file_get_contents($file1->getPathname())); $entity->setPhoto('/imgs/upload/service/' . $filename1); } $file2 = $entity->getFormIcon(); if ($file2) { $filename2 = uniqid() . '.' . $file2->getClientOriginalExtension(); $this->filesystem->write($filename2, file_get_contents($file2->getPathname())); $entity->setIcon('/imgs/upload/service/' . $filename2); } $file3 = $entity->getFormTopPhoto(); if ($file3) { $filename3 = uniqid() . '.' . $file3->getClientOriginalExtension(); $this->filesystem->write($filename3, file_get_contents($file3->getPathname())); $entity->setTopPhoto('/imgs/upload/service/' . $filename3); } $file4 = $entity->getFormDescriptionPhoto(); if ($file4) { $filename4 = uniqid() . '.' . $file4->getClientOriginalExtension(); $this->filesystem->write($filename4, file_get_contents($file4->getPathname())); $entity->setDescriptionPhoto('/imgs/upload/service/' . $filename4); } $file5 = $entity->getFormBenefitPhoto(); if ($file5) { $filename5 = uniqid() . '.' . $file5->getClientOriginalExtension(); $this->filesystem->write($filename5, file_get_contents($file5->getPathname())); $entity->setBenefitPhoto('/imgs/upload/service/' . $filename5); } $file6 = $entity->getFormIndicationPhoto(); if ($file6) { $filename6 = uniqid() . '.' . $file6->getClientOriginalExtension(); $this->filesystem->write($filename6, file_get_contents($file6->getPathname())); $entity->setIndicationPhoto('/imgs/upload/service/' . $filename6); } $file7 = $entity->getFormPreparationPhoto(); if ($file7) { $filename7 = uniqid() . '.' . $file7->getClientOriginalExtension(); $this->filesystem->write($filename7, file_get_contents($file7->getPathname())); $entity->setPreparationPhoto('/imgs/upload/service/' . $filename7); }
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 $file1 = $entity->getFormPhoto(); if ($file1) { $filename1 = uniqid() . '.' . $file1->getClientOriginalExtension(); $this->filesystem->write($filename1, file_get_contents($file1->getPathname())); $entity->setPhoto('/imgs/upload/service/' . $filename1); } $file2 = $entity->getFormIcon(); if ($file2) { $filename2 = uniqid() . '.' . $file2->getClientOriginalExtension(); $this->filesystem->write($filename2, file_get_contents($file2->getPathname())); $entity->setIcon('/imgs/upload/service/' . $filename2); } $file3 = $entity->getFormTopPhoto(); if ($file3) { $filename3 = uniqid() . '.' . $file3->getClientOriginalExtension(); $this->filesystem->write($filename3, file_get_contents($file3->getPathname())); $entity->setTopPhoto('/imgs/upload/service/' . $filename3); } $file4 = $entity->getFormDescriptionPhoto(); if ($file4) { $filename4 = uniqid() . '.' . $file4->getClientOriginalExtension(); $this->filesystem->write($filename4, file_get_contents($file4->getPathname())); $entity->setDescriptionPhoto('/imgs/upload/service/' . $filename4); } $file5 = $entity->getFormBenefitPhoto(); if ($file5) { $filename5 = uniqid() . '.' . $file5->getClientOriginalExtension(); $this->filesystem->write($filename5, file_get_contents($file5->getPathname())); $entity->setBenefitPhoto('/imgs/upload/service/' . $filename5); } $file6 = $entity->getFormIndicationPhoto(); if ($file6) { $filename6 = uniqid() . '.' . $file6->getClientOriginalExtension(); $this->filesystem->write($filename6, file_get_contents($file6->getPathname())); $entity->setIndicationPhoto('/imgs/upload/service/' . $filename6); } $file7 = $entity->getFormPreparationPhoto(); if ($file7) { $filename7 = uniqid() . '.' . $file7->getClientOriginalExtension(); $this->filesystem->write($filename7, file_get_contents($file7->getPathname())); $entity->setPreparationPhoto('/imgs/upload/service/' . $filename7); }

preferences:
304.86 ms | 409 KiB | 459 Q