On 26/08/2012, at 4:09 AM, Ferenc Kovacs <tyr...@gmail.com> wrote: > 2012.08.25. 19:50, "Sebastian Krebs" <krebs....@gmail.com> ezt írta: >> >> Am 25.08.2012 18:38, schrieb Ferenc Kovacs: >> >>> >>> would this trigger a notice if $foo is not defined? >>> if yes, then it would be different from the current behavior of > the >>> ternary operator. >>> >>> >>> Couldn't believe it, thus I tested it myself >>> >>> >>> snip >>> >>> Don't know, what you are talking about, but the notice _is_ the >>> current behaiour and therefore: No difference. >>> >>> >>> Sorry, I messed up that email. What I wanted to say: >>> If it accepts unset variable, then I could see usecases for it, but then >>> it would behave differently than the current ternary. >>> If it doesn't accept unset variable then it would in line with what we >>> have, but I don't see any usecase for it, because I would have to set it >>> before checking that it is falsely or not, in which case I would set it >>> to the default if not set already. >>> >>> >>> >>> if no, then I would never use this. >>> I mean if I have to set the variable before the check, then I >>> would put >>> the check into the assignment. >>> >>> >>> The main thought about it was >>> >>> function foo ($bar = null) { >>> $bar = $bar ?: 'default'; >>> } >>> >>> >>> If you wanted to enforce the 'default' value to be the default if no >>> argument passed, then you could use $bar = 'default' in the method >>> signature. >>> So I guess that you use that construct to handle when the argument is >>> passed, but it contains a falsely value ("0", array(), 0, etc.). >>> I agree that this can be useful in some cases. >>> >>> >>> I _always_ use 'null' as default >>> >>> >>> For me, it isn't always null, sometimes it is boolean true/false, or an >>> empty array. >>> >>> >>> - If you want to omit a parameter, but want to set one after that, >>> you don't need to look whats the default: It's 'null' >>> >>> >>> my IDE takes care of that problem for me. >> >> >> Only works on the green field ;) And/or if you are alone ... >> >> >>> >>> - Ive often enough seen something like >>> >>> function foo ($limit = 10) { /* code */ } >>> // Somewhere else >>> function bar ($limit = 50) { /* code */ $foo($limit); /* code */} >>> // Even somewhere else >>> bar(); >>> >>> >>> same here. >> >> >> Same here :p >> >> >>> >>> -- >>> Ferenc Kovács >>> @Tyr43l - http://tyrael.hu >> >> >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > So you are saying that your (teams) IDE doesn't tell you the method > signature which contains also the default values? > I guess that the fact that many of the php core functions have optional > arguments and non null defaults must be really a PITA for you.
I think what he was alluding to is the problem where one changes the default. All usages of the method/function then need to be updated. Using null today is very much like using the proposed 'default' parameter skipping RFC. Cheers, David -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php