I'm trying to convert this C# method into PHP. What does the out in the second parameter mean?
public static bool Foo(string name, out string key)
Documentationref
public static function foo($str, &$key)
^
| Pass by reference
Please consider that in C# you must set a value in the calling method when using out
and sadly you can't directly translate that into PHP.
The out
keyword specifies that the parameter must be assigned to by the called method, and the value assigned will be passed back to the calling method. Check out MSDN for more info.
I don't think PHP has an equivalent for the required assignment behavior, but if you are converting the method body, and maintain that behavior internally, you should be able to convert it to a regular pass by reference parameter and maintain the same functionality.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With