DEV Community

Discussion on: Stack local functions in PHP

Collapse
 
kip13 profile image
kip

I think maybe your solution is apply Strategy Pattern or State Pattern, you need to analyze your situation and make the choice.

BTW function pushFunction( &$afunction ) { isn't neccesary, in PHP objects are assigned to variables with a identifier point, the same point always unless you clone the object.

A PHP reference is an alias, which allows two different variables to write to the same value. As of PHP 5, an object variable doesn't contain the object itself as value anymore. It only contains an object identifier which allows object accessors to find the actual object. When an object is sent by argument, returned or assigned to another variable, the different variables are not aliases: they hold a copy of the identifier, which points to the same object.
php.net/manual/en/language.oop5.re...

Collapse
 
eduardllach profile image
Eduard Llach

Good points!

The goal in the real project is different, and i'm not sure at all that Startegy pattern or State Patter will do what I was looking for.

But you've shown me an interesting new site! designpatternsphp.readthedocs.io

And true, & is not necessary here.

Thx!