Is it fine with PHP to assign NULL here?
Example:
public function prepare($sql, &$p = NULL) {
p is assigned by reference. I'm not sure 开发者_如何转开发if I can assign safely NULL here as default. Is that ok in this case?
Why would you want to have a default value for a parameter that is passed by reference? Isn't the basic point of pass-by-reference that you can change the original variable in the caller's scope? So if it has a default value, then you are not changing anything in the caller's scope, so what's the point?
The code will run perfectly fine even with error_reporting set to E_ALL & E_STRICT.
And regarding the whole pass-by-reference with a default value of null, I just see it as an optional variable, and thats ok. You should definitely ask yourself whether you really need the reference because php is pretty smart about handling this type of stuff for you!
compile it and see :)
If the function can work properly with $p being NULL, then you don't have any problems.
精彩评论