In ruby a lot of methods have the ! marker which usually means a variable will be modified in place. So you could do
p "HELLO".downcase!
which is the same as
s = "HELLO".downcase
p s
In php you can use a pointer with the ampersand & symbol before a variable to modify it in place, or handle the var as a pointer. But does a function modifier exist or variable modifier that would allow for in place modification of varibales like
$str = "hi world";
str_replace("hi", "world", &$str)
Even in Ruby, the
!versions of functions are alternative versions specifically created to modify the variable in place. I.e.downcaseanddowncase!are two completely different functions, the!is just a naming convention.In PHP, you can pass variables by reference into any function, as you have shown yourself, but this may not necessarily give you the expected result, entirely depending on what the function does internally with the variable. To get a result similar to Ruby, you’d have to define an alternative version of each function that modifies in place: