allowance of non-standard arguments, such as callbacks

3 views
Skip to first unread message

Brett Zamir

unread,
Apr 3, 2011, 1:32:43 AM4/3/11
to ph...@googlegroups.com
HI Kevin and all,

Kevin, would you be open to us adding functions as allowable arguments,
where the arguments don't exist (e.g., as the
arguments[arguments.length] last argument), as long as we make a note
about it being non-standard and that it could change if PHP changed?

I think functions like sleep() or even file_get_contents (though we
found another way for that) could benefit from having the ability to
support asynchronous behaviors. By doing it as the last argument, it
allows us to allow PHP to continue to add features (since a user could
simply know to update by adding more arguments to their existing calls)
and allows us the ability to add those PHP features in the future.

Yes, it would mean that someone who took advantage of our custom feature
would need to change their code if they wanted to update php.js versions
at times when we need to add additional arguments later for the sake of
an additional argument being added in PHP, but those who followed the
strict PHP path would always be safe (unless PHP changed their argument
order).

I think such behavior could be more practical for our users, not all of
whom would be purists, but who would like the familiarity of say using:

sleep(2, function () {});
file_get_contents('some_file', function () {}); // Here it could
detect that the last argument is a function and use that, even though it
is not the last possible argument in the formal parameter list.

It would also let us endorse better practices more suited to JavaScript.
Incidentally, I'm really eager to start having our functions support
CommonJS or possibly NodeJS-specific behaviors (e.g., doing sleep as
setTimeout()).

Thanks!
Brett

Reply all
Reply to author
Forward
0 new messages