Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore non-function callback arguments #8

Merged
merged 5 commits into from
Dec 28, 2012
Merged

Conversation

jsor
Copy link
Member

@jsor jsor commented Dec 27, 2012

Make it compliant with Promises/A+

@igorw
Copy link
Contributor

igorw commented Dec 27, 2012

I'm not a fan of ignoring invalid arguments. This type of thing should fail.

For public APIs checking the args and failing early and explicitly is usually a good idea.

IMO we should either keep it as is or add exceptions if the arg is not null and not callable.

public function typesDataProvider()
{
return array(
array('', 'empty string'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side note: you can use an assoc array where the key is the desc.

@igorw
Copy link
Contributor

igorw commented Dec 27, 2012

Do you know what the promises/a+ motivation is for ignoring invalid args? JS is careless about args anyway, so it's a slightly different story for PHP imho.

@igorw
Copy link
Contributor

igorw commented Dec 27, 2012

@briancavalier hi there. :) can you perhaps clarify this?

@jsor
Copy link
Member Author

jsor commented Dec 27, 2012

I was just following Promiss/A+. At the moment its just wrong, even worse, passing a truthy value as progress handler produces an infinite loop.

Throwing exceptions inside then() is synchronous behavior and not a good idea.

See also promises-aplus/promises-spec#25 for a lengthy discussion about it.

@igorw
Copy link
Contributor

igorw commented Dec 27, 2012

In PHP 5.4 we will have a callable type hint, so imo we should emulate that behaviour.

I suggest we check the args and then trigger a E_USER_NOTICE with trigger_error. That way the script will keep on running, the developer gets notified and it will be consistent in the future.

We should do that in addition to ignoring non-callable args.

EDIT: Thanks for the research btw!

@briancavalier
Copy link

Hey guys, yeah, you can read a lot of backstory over at promises-aplus/promises-spec#25.

Some of us felt that this type of error should be caught as early as possible and reported as loudly as possible, but the majority felt that all non-functions should be ignored. So, we went with the majority vote for the Promises/A+ spec. In when.js, our plan is to have when/debug report these types of obvious mistakes so that users can still find them as early as possible in development.

@jsor For sure, progress is a bit of a mess right now. It's actually outside of the Promises/A+ spec, and there's not yet a clear de facto standard. It's being discussed and worked on over at promises-aplus/progress-spec, so please do jump into the conversation there if you have ideas. There's also some good background reading cited in promises-aplus/progress-spec#3 about the trickiness with progress handling.

@jsor
Copy link
Member Author

jsor commented Dec 27, 2012

@briancavalier thanks a lot for the clarifications. Btw, my comment about about being "wrong" and the infinite loop was about my code (react/promise), not when.js :-)

@briancavalier
Copy link

@jsor no problem! And it wouldn't surprise me if when.js's progress handling still has some wonky edge cases, especially related to progress propagation through a promise chain :) (runs off to test progress handler infinite loops in when.js)

@@ -27,6 +27,10 @@ public function then($fulfilledHandler = null, $errorHandler = null, $progressHa
}
};
} else {
if (null !== $progressHandler) {
trigger_error('Invalid $progressHandler argument passed to then(), must be null or callable.', \E_USER_NOTICE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\E_USER_NOTICE can be just E_USER_NOTICE. Applies to the other instances as well.

@igorw igorw merged commit 9403107 into master Dec 28, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants