Is it wrong to use an instance of an object as an argument? For example, is this a bad practice for this?
myFunction(new Foo);
Or you should always do it like this:
$foo = new Foo;
myFunction($foo);
My specific scenario.
I ask because I am in a situation where I need to pass a lot of new objects to a method in order to “register” a bunch of plugins. This is something like this:
$imagePlugin = new ImagePlugin;
$videoPlugin = new VideoPlugin;
$audioPlugin = new AudioPlugin;
$myLibrary->registerPlugins(array(
$imagePlugin,
$videoPlugin,
$audioPlugin
));
I am wondering if, in order, in accordance with best practices, shorten it to the code below:
$myLibrary->registerPlugins(array(
new ImagePlugin,
new VideoPlugin,
new AudioPlugin
));
source
share