What would be the best practice to do this :
class AwesomeClass {
// Code
public function test()
{
foreach($objects->values as $v)
{
New SuperClass($v);
}
return $objects;
}
}
class SuperClass {
public function __construct($arg2)
{
return trim($arg2);
}
}
$rule_the_world = New AwesomeClass($arg1);
$king = $rule_the_world->test();
The previous code is obviously not working, I think I’m missing some major point of PHP OO.
It’s very difficult to decipher what you’re asking for, and the code you have is not recoverable.
Code Errors
There are several errors in your code that are illogical:
AwesomeClasshas no constructor.arg1tonew AwesomeClassmeaninglessarg1is never initializedIn
AwesomeClass::test(),objectsis never initialized and has no membervalue.New SuperClass(should benew, per standards) does nothing.__construct()cannot return a value.What You May Want
What I think you’re going for is something like this:
Note that it is redundant to create an
ArrayIteratorinstance whenarg1must already be an array, this is just an example.