Newbie question...
Is it possible to use a function's argument to pass code to be executed inside the function? Something like...
function myfunction($somecode)
{
$somecode;
}
myfunction("echo 'foo'");
Actual scenario: my function performs some image manipulation using Imagick...
function myfunction($imagePath)
{
$image = new Imagick($imagePath);
$image->gaussianBlurImage(0, 5);
}
myfunction("test.jpg");
I'd like to be able to specify the Imagick method to use on the image in a function argument, so I could have something like...
function myfunction($imagePath, $method)
{
$image = new Imagick($imagePath);
$image->$method;
}
myfunction("test.jpg", "thumbnailImage(100, 100)");
Is such a thing possible?
evalor pass a closure which accepts$imageas argument.myfunc($img, "thumbnail", 100, 100)would even look tidier.$methods that you will accept, and run through aswitch(). That way, you can handle exceptions / unknown methods.