Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Passing new value to object, within loop

$
0
0

Hello

 

If we pass a value to a object when creating it with __construct

$NewObject = new class($value)

Lets say our object is placed within a loop to do some further stuff

while(1 < 10)
{

$NewObject->doThis();
$NewObject->doThat();

1++;

}

Now, we want to pass the next value to the object, so it will doThis() and doThat in the loop, But currently, it will just perform doThis() and doThat() on the same value.

How is this professionally achieved?

We can destroy the object and put $NewObject = new class($value); inside the loop, But is there a better way?

 

Thanks in advance for any future help/thoughts.


Viewing all articles
Browse latest Browse all 13200

Trending Articles