Marcus,
thanks for taking the time to comment. I realise that you core dev guys have plenty to do.
if I gather correctly you do understand why people would like to do stuff like (and indeed did in early versions of php5 - I got caught out myself when the change was made):
myFunc(MyObj $o = null)
I personal feeling on the above is that is look nice (granted, a bad argument) and its so compact yet flexible.
I will keep following the discussion and hope that some thing can be done to support the functionality which the above syntax pertains to can be included in some form, and if not I guess I'l just have to reread the archive to get a better understanding of the issues and figure out have to code what I want to code according to a 'better' paradigm. :-)
anyway, thanks once again. PHP5 is still looking really good.
Marcus Boerger wrote:
Hello Jochem,
Tuesday, October 19, 2004, 4:34:40 PM, you wrote:
As a point of interest, the error message you get if you pass something to a function which has classhint on the relevant arg which is not an object is as follows:
"Fatal error: Argument 1 must not be null in ....."
Which is not strictly correct, but it got me thinking: maybe the guy that wrote the message was thinking ahead of a time when passing null for a classhinted arg would be allowed?
You think too much. At the time the message was written we weren't able to access the typename correctly or we were to lazy to do so.
I don't see the big deal in being allowed to set default values on typehinted args - from my point of view this would have the result that objects or the given class or the default value is allowed and nothing else. I also don't see it as PHP's responsibility to stop me writing code which experienced programmers would balk at e.g.
myFunc(MyObj $o = 'fooBar')
This code makes no sense at all and this bullshit is detectable at compile time. Since the default value cannot be anything dynamic we will catch such erros during compile time in order to strengthen code stability. We won't like to called fools because of allowing such mistakes.
In practice it makes no difference what the default value is or even if it is a value at all because the usefulness of the default is being able to check whether the object was passed or not (while letting the engine do the classhint check)
This means that the check which leds to an error would be done anyways but at runtime.
I am no PHP hero, but I'm not a noob either - and I think the argument that syntax would be confusing for beginners is a little silly - I remember trying to figure out the basics of OO, that was a nightmare in its own right. the point being the entry level to this functionality is way above what a beginner is capable of - if they can figure out how to do basic OO [in PHP] then they will be able to figure out using classhinted args with optional default values
Keeping the low spirit does not mean we cannot support good oo neither does it mean we can allow mistakes.
best regards marcus
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php