Evening Chaps,
Following on from discussion regarding assertion API in PHP, the
following RFC is now up for discussion:
https://wiki.php.net/rfc/expectations
Please do point out any missing sections or information, so that it can
be clarified as quickly as possible.
I hope this conveys the idea a bit clearer to everyone ?
Cheers
Joe
Quoted text · 8 lines
Evening Chaps,
Following on from discussion regarding assertion API in PHP, thefollowing RFC is now up for discussion:
https://wiki.php.net/rfc/expectations Please do point out any missing sections or information, so that itcan be clarified as quickly as possible.
I hope this conveys the idea a bit clearer to everyone ?Cheers
Joe
I like it, but I'd rather we just called them what they are and use AssertionException, because expect is really just a new assert statement, with a different name to avoid conflicting with assert() for backwards-compatibility :)
Otherwise, I have no objections.
Thanks.
Andrea Faulds
http://ajf.me/
Quoted text · 11 lines
Evening Chaps,
Following on from discussion regarding assertion API in PHP, thefollowing RFC is now up for discussion:
https://wiki.php.net/rfc/expectations Please do point out any missing sections or information, so that itcan be clarified as quickly as possible.
I hope this conveys the idea a bit clearer to everyone ?Cheers
JoeI like it, but I'd rather we just called them what they are and use AssertionException, because expect is really just a new assert statement, with a different name to avoid conflicting with
assert()for backwards-compatibility :)Otherwise, I have no objections.
Thanks.
I thought about it ...
For the sake of making the concept as simple as possible to convey in documentation, it is probably better to have a uniform name:
Expect throwing ExpectationException is intuitive to some degree, Expect throwing an AssertionException seems less so ...
Cheers
Joe
Hi Joe
I like your RFC and how it is explained. You might want to add to your explanations that ExpectationException is a subclass of ErrorException (as mentioned in the other thread). And I was just wondering what the default value will be for the ini property zend.expectations, maybe you could add this as well.
Cheers,
Robert
Quoted text · 16 lines
-----Original Message-----
From: Joe Watkins [mailto:[email protected]] Sent: Friday, October 18, 2013 11:47 PM
To: [email protected]
Subject: [PHP-DEV] RFC: ExpectationsEvening Chaps,
Following on from discussion regarding assertion API in PHP, the following RFC is now up for discussion:
https://wiki.php.net/rfc/expectations
Please do point out any missing sections or information, so that it can
be clarified as quickly as possible.I hope this conveys the idea a bit clearer to everyone ?
Cheers
Joe--
To unsubscribe,
visit:
http://www.php.net/unsub.php
I like it a lot.
Let's face the truth. Assertions is a huge mess. We have two options:
- Set it aside for now, and implement a better replacement
- Jump right in, clean up the mess, and not have a functional alternative until PHP 7.
+1 for expect.
Quoted text · 21 lines
Hi Joe
I like your RFC and how it is explained. You might want to add to your explanations that ExpectationException is a subclass of ErrorException (as mentioned in the other thread). And I was just wondering what the default value will be for the ini property zend.expectations, maybe you could add this as well.
Cheers,
Robert-----Original Message-----
From: Joe Watkins [mailto:[email protected]] Sent: Friday, October 18, 2013 11:47 PM
To: [email protected]
Subject: [PHP-DEV] RFC: ExpectationsEvening Chaps,
Following on from discussion regarding assertion API in PHP, thefollowing RFC is now up for discussion:
https://wiki.php.net/rfc/expectations Please do point out any missing sections or information, so that itcan
be clarified as quickly as possible.
I hope this conveys the idea a bit clearer to everyone ?Cheers
Joe--
To unsubscribe,
visit:
http://www.php.net/unsub.php
Quoted text · 20 lines
Hi Joe
I like your RFC and how it is explained. You might want to add to your explanations that ExpectationException is a subclass of ErrorException (as mentioned in the other thread). And I was just wondering what the default value will be for the ini property zend.expectations, maybe you could add this as well.
Cheers,
Robert-----Original Message-----
From: Joe Watkins [mailto:[email protected]] Sent: Friday, October 18, 2013 11:47 PM
To: [email protected]
Subject: [PHP-DEV] RFC: ExpectationsEvening Chaps,
Following on from discussion regarding assertion API in PHP, the following RFC is now up for discussion:
https://wiki.php.net/rfc/expectations
Please do point out any missing sections or information, so that it can
be clarified as quickly as possible.I hope this conveys the idea a bit clearer to everyone ?
Cheers
Joe--
To unsubscribe,
visit:
http://www.php.net/unsub.php
I have added the ErrorException info.
It does say zend.expectations=1 in the config section, I'm not able to say what production/dev default settings will be.
Cheers
Joe
It does say zend.expectations=1 in the config section, I'm not able to say what production/dev default settings will be.
I would assume that you'd want to state in the RFC that it would be default '1' in development, and default '0' in production. Based upon the so far discussed use cases.
Eli
It does say zend.expectations=1 in the config section, I'm not able to say what production/dev default settings will be.
I would assume that you'd want to state in the RFC that it would be default '1' in development, and default '0' in production. Based upon the so far discussed use cases.
Eli
Have updated the note with clarity ...
Cheers
Joe
Quoted text · 8 lines
Evening Chaps,
Following on from discussion regarding assertion API in PHP, thefollowing RFC is now up for discussion:
https://wiki.php.net/rfc/expectations Please do point out any missing sections or information, so that itcan be clarified as quickly as possible.
I hope this conveys the idea a bit clearer to everyone ?Cheers
Joe
I have added some performance information in comparison to the legacy assertion API, because I'm not sure it's obvious ...
It is definitely worth looking at ... definitely ...
Cheers
Joe
Hi,
Quoted text · 8 lines
Evening Chaps,
Following on from discussion regarding assertion API in PHP, thefollowing RFC is now up for discussion:
https://wiki.php.net/rfc/**expectations<https://wiki.php.net/rfc/expectations> Please do point out any missing sections or information, so thatit can be clarified as quickly as possible.
I hope this conveys the idea a bit clearer to everyone ?Cheers
Joe
I think it's a nice idea. However I am not so sure if it's worthy introducing a new keyword 'except' which will break all existing code where except is used as a function name, class name... Could it be actually mentioned in the RFC that there is a new keyword? It's quite clear from the examples but it would be nice if it could be specified as it's quite important IMHO.
In addition I have got more technical question about using ext functions in engine. I saw that you used php_trim in zend_compile.c. Is it a good idea to do that? Wouldn't be better to create a new function (for example zend_str_trim) in the engine (zend_operator.c comes to my mind as it contains zend_str_tolower and other similar function) and then use this function by php_trim?
Jakub
Quoted text · 12 lines
Hi,
Evening Chaps,
Following on from discussion regarding assertion API in PHP, thefollowing RFC is now up for discussion:
https://wiki.php.net/rfc/**expectations<https://wiki.php.net/rfc/expectations> Please do point out any missing sections or information, so thatit can be clarified as quickly as possible.
I hope this conveys the idea a bit clearer to everyone ?Cheers
JoeI think it's a nice idea. However I am not so sure if it's worthy introducing a new keyword 'except' which will break all existing code where except is used as a function name, class name... Could it be actually mentioned in the RFC that there is a new keyword? It's quite clear from the examples but it would be nice if it could be specified as it's quite important IMHO.
In addition I have got more technical question about using ext functions in engine. I saw that you used php_trim in zend_compile.c. Is it a good idea to do that? Wouldn't be better to create a new function (for example zend_str_trim) in the engine (zend_operator.c comes to my mind as it contains zend_str_tolower and other similar function) and then use this function by php_trim?
Jakub
It would appear a new keyword is required.
I wasn't sure about php_trim either, I'll see what can be done there ...
Cheers
Joe
Quoted text · 12 lines
Hi,
Evening Chaps,
Following on from discussion regarding assertion API in PHP, thefollowing RFC is now up for discussion:
https://wiki.php.net/rfc/**expectations<https://wiki.php.net/rfc/expectations> Please do point out any missing sections or information, so thatit can be clarified as quickly as possible.
I hope this conveys the idea a bit clearer to everyone ?Cheers
JoeI think it's a nice idea. However I am not so sure if it's worthy introducing a new keyword 'except' which will break all existing code where except is used as a function name, class name... Could it be actually mentioned in the RFC that there is a new keyword? It's quite clear from the examples but it would be nice if it could be specified as it's quite important IMHO.
In addition I have got more technical question about using ext functions in engine. I saw that you used php_trim in zend_compile.c. Is it a good idea to do that? Wouldn't be better to create a new function (for example zend_str_trim) in the engine (zend_operator.c comes to my mind as it contains zend_str_tolower and other similar function) and then use this function by php_trim?
Jakub
Removed dependency on php_trim ...
Cheers
Joe
Heya,
I do not know how much it concerns this RFC but I came across the following page about an extension named "Expect" when I was searching for RFC Expect with google.
http://php.net/manual/en/book.expect.php
I suppose there would be a name clash between the extension and the new expect keyword. I do not know how internals usually deal with such problems, especially if it is within an extension, but I am sure someone will know it.
Cheers,
Robert
Quoted text · 16 lines
-----Original Message-----
From: Joe Watkins [mailto:[email protected]] Sent: Friday, October 18, 2013 11:47 PM
To: [email protected]
Subject: [PHP-DEV] RFC: ExpectationsEvening Chaps,
Following on from discussion regarding assertion API in PHP, the following RFC is now up for discussion:
https://wiki.php.net/rfc/expectations
Please do point out any missing sections or information, so that it can
be clarified as quickly as possible.I hope this conveys the idea a bit clearer to everyone ?
Cheers
Joe--
To unsubscribe,
visit:
http://www.php.net/unsub.php
Quoted text · 7 lines
Heya,
I do not know how much it concerns this RFC but I came across the following page about an extension named "Expect" when I was searching for RFC Expect with google.
http://php.net/manual/en/book.expect.phpI suppose there would be a name clash between the extension and the new expect keyword. I do not know how internals usually deal with such problems,
especially if it is within an extension, but I am sure someone will know it.Cheers,
Robert
it was discussed on irc, there is not problem here, because the ext name and the function name can't clash, and the ext doesn't have a function with the name of expect, so everything is fine afaik.
--
Ferenc Kovács
@Tyr43l - http://tyrael.hu
Quoted text · 8 lines
Heya,
I do not know how much it concerns this RFC but I came across the following page about an extension named "Expect" when I was searching for RFC Expect with google.
http://php.net/manual/en/book.expect.phpI suppose there would be a name clash between the extension and the new expect keyword. I do not know how internals usually deal with such problems,
especially if it is within an extension, but I am sure someone will know it.Cheers,
Robertit was discussed on irc, there is not problem here, because the ext name and the function name can't clash, and the ext doesn't have a function with the name of expect, so everything is fine afaik.
Yeah, just to confirm, that's correct.
Cheers
Joe
Quoted text · 8 lines
Heya,
I do not know how much it concerns this RFC but I came across the following page about an extension named "Expect" when I was searching for RFC Expect with google.
http://php.net/manual/en/book.expect.phpI suppose there would be a name clash between the extension and the new expect keyword. I do not know how internals usually deal with such problems,
especially if it is within an extension, but I am sure someone will know it.Cheers,
Robertit was discussed on irc, there is not problem here, because the ext name and the function name can't clash, and the ext doesn't have a function with the name of expect, so everything is fine afaik.
Rasmus has pointed out that there is an expect:// stream wrapper.
So looks like we need a new name ?? Ideas ??
Cheers
Joe
So looks like we need a new name ?? Ideas ??
Hmm... posit, assume, demand, presume. I rather like demand; it has that air of be-true-or-else that fits the occasion.
--
Bob Williams
Notice: This communication, including attachments, may contain information that is confidential. It constitutes non-public information intended to be conveyed only to the designated recipient(s). If the reader or recipient of this communication is not the intended recipient, an employee or agent of the intended recipient who is responsible for delivering it to the intended recipient, or if you believe that you have received this communication in error, please notify the sender immediately by return e-mail and promptly delete this e-mail, including attachments without reading or saving them in any manner. The unauthorized use, dissemination, distribution, or reproduction of this e-mail, including attachments, is prohibited and may be unlawful. If you have received this email in error, please notify us immediately by e-mail or telephone and delete the e-mail and the attachments (if any).
Since this would throw exceptions, could it look like (or be) a final/abstract (although PHP doesn't allow that combo for some reason) class with static methods?
Assert::isTrue($expr, $msg);
That syntax is already valid (so of course there are BC issues) and I don't know how practical it is to optimize that away to nothing, but it would be more consistent with regard to throwing exceptions and would allow for a variety of different class methods.
--
Matthew Leverton
Quoted text · 15 lines
Heya,
I do not know how much it concerns this RFC but I came across the following
page about an extension named "Expect" when I was searching for RFC Expect
with google.
http://php.net/manual/en/book.expect.phpI suppose there would be a name clash between the extension and the new expect keyword. I do not know how internals usually deal with such problems,
especially if it is within an extension, but I am sure someone will know it.Cheers,
Robertit was discussed on irc, there is not problem here, because the ext name and the function name can't clash, and the ext doesn't have a function with
the name of expect, so everything is fine afaik.Rasmus has pointed out that there is an expect:// stream wrapper.
So looks like we need a new name ?? Ideas ??
Cheers
Joe
Matthew Leverton wrote (on 21/10/2013):
final/abstract (although PHP doesn't allow that combo for some reason)
Final means "cannot be sub-classed", abstract means "must be sub-classed"; the combination would make no sense. Specifically, it would allow completely illogical code like "final abstract class Foo { abstract public function some_method(); }"
Incidentally, Java doesn't allow this combination either; this isn't PHP being picky.
The logical declaration for a class that can only be used statically would be "static class Foo { ... }". The combination "abstract static" also makes sense (for a static class with missing method bodies). There's an ancient RFC proposing that here, but it seems it didn't get anywhere much: https://wiki.php.net/rfc/static-classes
Regards,
Rowan Collins
[IMSoP]
Quoted text · 13 lines
Heya,
I do not know how much it concerns this RFC but I came across the following
page about an extension named "Expect" when I was searching for RFC Expect
with google.
http://php.net/manual/en/book.**expect.phphttp://php.net/manual/en/book.expect.phpI suppose there would be a name clash between the extension and the new expect keyword. I do not know how internals usually deal with such problems,
especially if it is within an extension, but I am sure someone will know it.Cheers,
Robertit was discussed on irc, there is not problem here, because the ext name and the function name can't clash, and the ext doesn't have a function with
the name of expect, so everything is fine afaik.Rasmus has pointed out that there is an expect:// stream wrapper.
So looks like we need a new name ?? Ideas ??
Why ?
The stream wrapper is always used in a string, so there is no parsing problem about the "expect" keyword.
Am I missing something ?
Julien.Pauli
Quoted text · 17 lines
Heya,
I do not know how much it concerns this RFC but I came across the following
page about an extension named "Expect" when I was searching for RFC Expect
with google.
http://php.net/manual/en/book.**expect.phphttp://php.net/manual/en/book.expect.phpI suppose there would be a name clash between the extension and the new expect keyword. I do not know how internals usually deal with such problems,
especially if it is within an extension, but I am sure someone will know it.Cheers,
Robertit was discussed on irc, there is not problem here, because the ext name and the function name can't clash, and the ext doesn't have a function with
the name of expect, so everything is fine afaik.Rasmus has pointed out that there is an expect:// stream wrapper.
So looks like we need a new name ?? Ideas ??
Why ?
The stream wrapper is always used in a string, so there is no parsing problem about the "expect" keyword.
Am I missing something ?Julien.Pauli
Morning Julien,
I don't think you're missing anything, there's still no clash introduced in code ... there might be in minds though, I can see that ...
Would be nice to get others' opinion, should we work to avoid this clash or will we be okay, is the difference obvious ?
Cheers
Joe
Am 21.10.2013 03:52 schrieb "Joe Watkins" [email protected]:
So looks like we need a new name ?? Ideas ??
abstract EXPRESSION
abstract is already a keyword, so no BC.
abstract is not concrete so alludes a bit to the might-be-or-might-not-be-checked nature of the test
abstract is the name for the "short summary" intro part of scientific papers, and these conditions are kind of a summary of what is known (preconditions) and concluded (postconditions).
best regards
Patrick
Am 21.10.2013 03:52 schrieb "Joe Watkins" [email protected]:
So looks like we need a new name ?? Ideas ??
abstract EXPRESSION
wat?
abstract is already a keyword, so no BC.
abstract is not concrete so alludes a bit to the might-be-or-might-not-be-checked nature of the test
abstract is the name for the "short summary" intro part of scientific papers, and these conditions are kind of a summary of what is known (preconditions) and concluded (postconditions).
Ah, ok well. I'd rather go for expected() or except() then...
--
Regards,
Mike
Quoted text · 8 lines
Am 21.10.2013 03:52 schrieb "Joe Watkins" [email protected]:
So looks like we need a new name ?? Ideas ??
abstract EXPRESSION
wat?
abstract is already a keyword, so no BC.
abstract is not concrete so alludes a bit to the might-be-or-might-not-be-checked nature of the test
abstract is the name for the "short summary" intro part of scientific papers, and these conditions are kind of a summary of what is known (preconditions) and concluded (postconditions).
Ah, ok well. I'd rather go for expected() or except() then...
Expected appears to be the most suitable solution suggested so far ...
I was following along with the abstract suggestion, I thought that was pretty well thought out, but a bit hard to explain why we are re-using the abstract keyword for something that is completely unrelated to abstract classes all the same ...
So for those that see the problem does Expected work around it ??
Cheers
Joe
Quoted text · 14 lines
Am 21.10.2013 03:52 schrieb "Joe Watkins" [email protected]:
So looks like we need a new name ?? Ideas ??
abstract EXPRESSION
wat?
abstract is already a keyword, so no BC.
abstract is not concrete so alludes a bit to the might-be-or-might-not-be-checked nature of the test
abstract is the name for the "short summary" intro part of scientific
papers, and these conditions are kind of a summary of what is known (preconditions) and concluded (postconditions).Ah, ok well. I'd rather go for expected() or except() then...
Expected appears to be the most suitable solution suggested so far ...
I was following along with the abstract suggestion, I thought that was pretty well thought out, but a bit hard to explain why we are re-using the abstract keyword for something that is completely unrelated to abstract classes all the same ...
So for those that see the problem does Expected work around it ??
Cheers
Joe
This proposal sounds a lot like exceptions to me or am I missing something :/
Could we do something like throw new expectation($expects, $message);
This proposal sounds a lot like exceptions to me or am I missing something :/
Could we do something like throw new expectation($expects, $message);
Er, T_EXPECT will be essentially a clone of Java and Python's assert statement, but not called assert because of the existing assert() function (and backwards-compatibility is PHP's middle name).
Unless you mean the similar name. Well, I don't think "exception" and "expect" can be confused (though as someone who used to use Python, I keep reading this as "except", Python's equivalent to "catch"), though "ExpectationException" might be confusing. I think we should name it "AssertionException".
--
Andrea Faulds
http://ajf.me/
Quoted text · 4 lines
This proposal sounds a lot like exceptions to me or am I missing something :/
Could we do something like throw new expectation($expects, $message);Er, T_EXPECT will be essentially a clone of Java and Python's assert statement, but not called assert because of the existing
assert()function (and backwards-compatibility is PHP's middle name).Unless you mean the similar name. Well, I don't think "exception" and "expect" can be confused (though as someone who used to use Python, I keep reading this as "except", Python's equivalent to "catch"), though "ExpectationException" might be confusing. I think we should name it "AssertionException".
I think it would be more confusing for expect to throw an AssertionException.
Cheers
Joe
Quoted text · 15 lines
Am 21.10.2013 03:52 schrieb "Joe Watkins" [email protected]:
So looks like we need a new name ?? Ideas ??
abstract EXPRESSION
wat?
abstract is already a keyword, so no BC.
abstract is not concrete so alludes a bit to the might-be-or-might-not-be-checked nature of the test
abstract is the name for the "short summary" intro part of scientific papers, and these conditions are kind of a summary of what is known (preconditions) and concluded (postconditions).
Ah, ok well. I'd rather go for expected() or except() then...
Expected appears to be the most suitable solution suggested so far ...
I was following along with the abstract suggestion, I thought that was pretty well thought out, but a bit hard to explain why we are re-using the abstract keyword for something that is completely unrelated to abstract classes all the same ...
So for those that see the problem does Expected work around it ??
Cheers
JoeThis proposal sounds a lot like exceptions to me or am I missing something :/
Could we do something like throw new expectation($expects, $message); Yes, you are missing something.
Quoted text · 8 lines
Am 21.10.2013 03:52 schrieb "Joe Watkins" [email protected]:
So looks like we need a new name ?? Ideas ??
abstract EXPRESSION
wat?
abstract is already a keyword, so no BC.
abstract is not concrete so alludes a bit to the might-be-or-might-not-be-checked nature of the test
abstract is the name for the "short summary" intro part of scientific papers, and these conditions are kind of a summary of what is known (preconditions) and concluded (postconditions).
Ah, ok well. I'd rather go for expected() or except() then...
Since we're throwing around terms, here's another one:
predicate <expr>;
It should be understood by most programmers what it means (though, admittedly, it doesn't carry an obvious severity) and isn't used anywhere in the language (afaik).
Quoted text · 4 lines
--
Regards,
Mike--
--
Tjerk
Quoted text · 15 lines
Am 21.10.2013 03:52 schrieb "Joe Watkins" [email protected]:
So looks like we need a new name ?? Ideas ??
abstract EXPRESSION
wat?
abstract is already a keyword, so no BC.
abstract is not concrete so alludes a bit to the might-be-or-might-not-be-checked nature of the test
abstract is the name for the "short summary" intro part of scientific papers, and these conditions are kind of a summary of what is known (preconditions) and concluded (postconditions).
Ah, ok well. I'd rather go for expected() or except() then...
Since we're throwing around terms, here's another one:
predicate <expr>;
It should be understood by most programmers what it means (though, admittedly, it doesn't carry an obvious severity) and isn't used anywhere in the language (afaik).
--
Regards,
Mike--
I suggest we process thusly:
We need some consensus as to whether this is actually a problem or not
before we get lost in suggestions ...
Should we decide it's a problem then we need to decide if using the keyword "expected" solves the problem ... Should there still be a problem we should compile a short list and get a consensus on it before proceeding to make necessary changes.
So first of all, can we get a quick +|-1 on:
Using "expect" is a problem
Using "expected" solves the problem
We can proceed from there I think ...
Cheers
Joe
Quoted text · 5 lines
Evening Chaps,
Following on from discussion regarding assertion API in PHP, the following RFC is now up for discussion:
https://wiki.php.net/rfc/expectations
Please do point out any missing sections or information, so that it can be clarified as quickly as possible.
I hope this conveys the idea a bit clearer to everyone ?
This is again an RFC that does not even attempt to argue for its usefulness. "This functionality was meant to replace the assert() API that currently exists in PHP, because of problems replacing it in a compatible manner". This doesn't say what is wrong with assert() or whether we need expect.
Besides that, why support execptions here. asserts are for testing things in development in order not to cock things up. Using exceptions for this makes very little sense. All of your examples even promote to handle exceptions and continue with excecution. If you want that, just use normal if()s with exceptions. I don't see the point of yet another syntax extension to do things you can already do just fine.
cheers,
Derick
Quoted text · 9 lines
Evening Chaps,
Following on from discussion regarding assertion API in PHP, the following RFC is now up for discussion:
https://wiki.php.net/rfc/expectations
Please do point out any missing sections or information, so that it can be clarified as quickly as possible.
I hope this conveys the idea a bit clearer to everyone ?
This is again an RFC that does not even attempt to argue for its usefulness. "This functionality was meant to replace the
assert()API that currently exists in PHP, because of problems replacing it in a compatible manner". This doesn't say what is wrong withassert()or whether we need expect.Besides that, why support execptions here. asserts are for testing things in development in order not to cock things up. Using exceptions for this makes very little sense. All of your examples even promote to handle exceptions and continue with excecution. If you want that, just use normal if()s with exceptions. I don't see the point of yet another syntax extension to do things you can already do just fine.
cheers,
Derick
The performance of the current assert API is unacceptable during development due to the fact it is a function that utilizes strings and eval, and cannot be disabled completely during production because it's a function not a language construct. This makes it quite devastating to deploy, it seems obvious we should seek to replace it.
We should support exceptions here because it gives a reasonable way to manage the error without impacting anything else, without requiring module globals, ini settings, or supporting functions in userland. By manage I do not necessarily mean continue executing, I mean that it is never really acceptable or useful for a web application to quit, writing a single exception to standard error. It is useful to be able to manage the error to collect more information about the state of the application, gain access to a stack trace, and do something actually useful.
Not all of the examples promote continuing execution, at all, I think only one actually does. I mention once that continuing execution is an option, just like it is when you catch any other exception.
Cheers
Joe
Quoted text · 8 lines
Evening Chaps,
Following on from discussion regarding assertion API in PHP, the following RFC is now up for discussion:
https://wiki.php.net/rfc/expectations
Please do point out any missing sections or information, so that it can be clarified as quickly as possible.
I hope this conveys the idea a bit clearer to everyone ?
This is again an RFC that does not even attempt to argue for its usefulness. "This functionality was meant to replace the
assert()API that currently exists in PHP, because of problems replacing it in a compatible manner". This doesn't say what is wrong withassert()or whether we need expect.Besides that, why support execptions here. asserts are for testing things in development in order not to cock things up. Using exceptions for this makes very little sense. All of your examples even promote to handle exceptions and continue with excecution. If you want that, just use normal if()s with exceptions. I don't see the point of yet another syntax extension to do things you can already do just fine.
The performance of the current assert API is unacceptable during development due to the fact it is a function that utilizes strings and eval, and cannot be disabled completely during production because it's a function not a language construct. This makes it quite devastating to deploy, it seems obvious we should seek to replace it.
I wasn't arguing about its merits, only that the RFC should contain the whole story of why we want to change the language. IMO RFCs often only including weak reasons and there needs to be a really strong case (not like "I don't like how it works" or "I'd like this to thrown exceptions") for changing the language. Don't take changing the language and/or syntax to lightly.
We should support exceptions here because it gives a reasonable way to manage the error without impacting anything else, without requiring module globals, ini settings, or supporting functions in userland.
Not part of my original email, but I disagree here. An assertion/expectation is a last moment resort which should abort an application as to prevent harm being done, just like the C library's "assert":
ASSERT(3) Linux Programmer's Manual
ASSERT(3)
NAME
assert - abort the program if assertion is false
By manage I do not necessarily mean continue executing, I mean that it is never really acceptable or useful for a web application to quit, writing a single exception to standard error. It is useful to be able to manage the error to collect more information about the state of the application, gain access to a stack trace, and do something actually useful.
You're contradicting yourself here. You say that you don't necessarily want to continue executing, but that's exactly what handling exception handling does. You're now changing "assertions" to something that has parts that are always available (the exception handling) and things that are compiled out (the "expectations") - which doesn't make a lot of sense to me. You don't need "expectations" for this as you can already do this just fine (by throwing exceptions).
I'm pretty convinced that expectations without exceptions are a good idea, as using assert (which is really eval) is a nasty thing that should be replaced, but IMO exception throwing should not be part of this feature.
cheers,
Derick
--
http://derickrethans.nl | http://xdebug.org Like Xdebug? Consider a donation: http://xdebug.org/donate.php twitter: @derickr and @xdebug
Posted with an email client that doesn't mangle email: alpine
Quoted text · 15 lines
Evening Chaps,
Following on from discussion regarding assertion API in PHP, the following RFC is now up for discussion:
https://wiki.php.net/rfc/expectations
Please do point out any missing sections or information, so that it can be clarified as quickly as possible.
I hope this conveys the idea a bit clearer to everyone ? This is again an RFC that does not even attempt to argue for its usefulness. "This functionality was meant to replace the
assert()API that currently exists in PHP, because of problems replacing it in a compatible manner". This doesn't say what is wrong withassert()or whether we need expect.Besides that, why support execptions here. asserts are for testing things in development in order not to cock things up. Using exceptions for this makes very little sense. All of your examples even promote to handle exceptions and continue with excecution. If you want that, just use normal if()s with exceptions. I don't see the point of yet another syntax extension to do things you can already do just fine. The performance of the current assert API is unacceptable during development due to the fact it is a function that utilizes strings and eval, and cannot be disabled completely during production because it's a function not a language construct. This makes it quite devastating to deploy, it seems obvious we should seek to replace it. I wasn't arguing about its merits, only that the RFC should contain the whole story of why we want to change the language. IMO RFCs often only including weak reasons and there needs to be a really strong case (not like "I don't like how it works" or "I'd like this to thrown exceptions") for changing the language. Don't take changing the language and/or syntax to lightly.
We should support exceptions here because it gives a reasonable way to manage the error without impacting anything else, without requiring module globals, ini settings, or supporting functions in userland. Not part of my original email, but I disagree here. An assertion/expectation is a last moment resort which should abort an application as to prevent harm being done, just like the C library's "assert":
ASSERT(3) Linux Programmer's Manual ASSERT(3)
NAME
assert - abort the program if assertion is falseBy manage I do not necessarily mean continue executing, I mean that it is never really acceptable or useful for a web application to quit, writing a single exception to standard error. It is useful to be able to manage the error to collect more information about the state of the application, gain access to a stack trace, and do something actually useful.
You're contradicting yourself here. You say that you don't necessarily want to continue executing, but that's exactly what handling exception handling does. You're now changing "assertions" to something that has parts that are always available (the exception handling) and things that are compiled out (the "expectations") - which doesn't make a lot of sense to me. You don't need "expectations" for this as you can already do this just fine (by throwing exceptions).I'm pretty convinced that expectations without exceptions are a good idea, as using assert (which is really eval) is a nasty thing that should be replaced, but IMO exception throwing should not be part of this feature.
cheers,
Derick
Morning Derick,
I'd like to say that, I thought this must be the case, there is no way Derick is asking me to justify assertion ... @internals can be a bit heated, I dunno why, we are all reasonable chaps :)
I think C is the wrong direction to look for inspiration here, there are plenty of implementations of assertion that do throw exceptions, I've linked to them in the RFC yesterday. The reasons should be palatable; an exception provides a stack trace, it allows the failure to be graceful.
It does not promote continuing execution, and if you look with a cool head on you can see I done that once, only to show that: I have not changed what an exception is, that an ExpectationException does change what Zend does, that it will not intrude on the expected behaviour of any aspect in any case
The reasons C should immediately abort do not stand here, when an assertion fails in C it can do useful things; generate a core dump and quit. We cannot do that, we must allow the programmer to collect state and other information to help them avoid the same exception again. All of the modern implementations of assertion do exactly the same thing, even our old implementation takes a callback (requiring module globals and all that junk) for what I can only imagine are the same reasons.
So with the fact established that errors should be manageable, and is it a fact; we can do one of two things, we can accept a callback, which requires module globals, ini settings, userland functions .. or it we can support it where the feature actually is, at the level of Zend, in the language.
It seems elegant and obvious to allow failed assertions to throw exceptions and for them to be managed as any other exception in PHP, or not - which DOES result in abortion, lets not forget that fact. I'm not sure the examples show this, but the majority of them are copied verbatim from the Java documentation of the same feature, we appear to disagree on the ones I thought I would drop in.
Perhaps my mistake, I don't know ... to be clear: This is implemented as it is in Java and a few other modern implementations besides, I am not changing what assertions are, where they should and shouldn't be used and what for, it is exactly the same as Java, intended to be used just as it is in Java, another high level programming language. Ruby is the same, and three independent implementations for various Javascript engines, all high level implementations ...
So certainly, I'm not alone in my assertion; we should definitely use exceptions.
About the lacking info in the RFC, the information you seek to have included is actually there, the original thread is referenced, I'm not sure it is necessary to reproduce the essence of the conversation in the RFC, by the time it was written certain facts seemed all but established, so I thought I would start from where we were then, rather than from the beginning of the original thread.
It's all very well to say lets not take implementation or change too lightly, but then, we do have an absolutely terrible implementation of assertion, that pernicious decision was allowed to pass without anyone pointing out that certain things are absolutely required from an implementation of assertion for it to be considered useful, it was short sighted and unnecessary to include an implementation of something that requires support by the engine for it to be usable the way it is intended to be used.
I'm not taking anything lightly, I'm solving an actual problem here, not introducing something new, but properly supporting something we are documented to support.
Cheers
Joe
I'm pretty convinced that expectations without exceptions are a good idea, as using assert (which is really eval) is a nasty thing that should be replaced, but IMO exception throwing should not be part of this feature.
I agree that something to replace the eval-based assert() would be good. What if the new syntax simply respected assert_options(), and assert_options() was extended to support an explicit ASSERT_EXCEPTION control option (that presumably took an exception class name as its option value)? That seems like it would provide the exception based possibilities that some posters want while maintaining the same assertion behaviour that users are already used to by default.
Adam, who apologises if this has been suggested before — this was a long set of threads and I've been busy.
Quoted text · 4 lines
I'm pretty convinced that expectations without exceptions are a good idea, as using assert (which is really eval) is a nasty thing that should be replaced, but IMO exception throwing should not be part of this feature.
I agree that something to replace the eval-basedassert()would be good. What if the new syntax simply respectedassert_options(), andassert_options()was extended to support an explicitASSERT_EXCEPTIONcontrol option (that presumably took an exception class name as its option value)? That seems like it would provide the exception based possibilities that some posters want while maintaining the same assertion behaviour that users are already used to by default.Adam, who apologises if this has been suggested before — this was a long set of threads and I've been busy.
I'm a bit perplexed at the need to retain any compatibility with what is a poor implementation ?
I've mentioned that retaining compatibility is a restriction on this implementation, I guess assuming the reasons were obvious. I've brushed over them, but to be explicit, backwards compatible means multiple ini settings, at least one userland function, module globals, and confusion. It means being able to disable and enable assertions at runtime, impacting the implementation and every op array that uses it in production environments. All these things make the implementation less suitable as an implementation of assertion and I do not see a need to restrict it in this way.
Cheers
Joe
I agree that something to replace the eval-based
assert()would be good. What if the new syntax simply respectedassert_options(), andassert_options()was extended to support an explicitASSERT_EXCEPTIONcontrol option (that presumably took an exception class name as its option value)? That seems like it would provide the exception based possibilities that some posters want while maintaining the same assertion behaviour that users are already used to by default.I'm a bit perplexed at the need to retain any compatibility with what is a poor implementation ?
To be fair, I think part of the disconnect here is that I don't feel like the current implementation is particularly poor besides the eval-based API. I don't really want an assertion failure to throw an exception — if I did, I'd use an assert callback or ErrorException to do that. I want it logged so I can look at it later, and that's easily configured with the current assertion setup.
I guess I'm wondering if there's a middle ground here, rather than throwing the assertion baby out with the bathwater in favour of an entirely new thing that could simply be syntax sugar sprinkled over an existing, working implementation.
Adam
Quoted text · 5 lines
I agree that something to replace the eval-based
assert()would be good. What if the new syntax simply respectedassert_options(), andassert_options()was extended to support an explicitASSERT_EXCEPTIONcontrol option (that presumably took an exception class name as its option value)? That seems like it would provide the exception based possibilities that some posters want while maintaining the same assertion behaviour that users are already used to by default.I'm a bit perplexed at the need to retain any compatibility with what is a poor implementation ?
To be fair, I think part of the disconnect here is that I don't feel like the current implementation is particularly poor besides the eval-based API. I don't really want an assertion failure to throw an exception — if I did, I'd use an assert callback or ErrorException to do that. I want it logged so I can look at it later, and that's easily configured with the current assertion setup.
I guess I'm wondering if there's a middle ground here, rather than throwing the assertion baby out with the bathwater in favour of an entirely new thing that could simply be syntax sugar sprinkled over an existing, working implementation.
Adam
You can catch exceptions, and log them.
You can do that without impacting everything around you, you can do that, or whatever else you like.
There is one camp saying we want to catch exceptions and have access to stack traces and the current scope, others who say that there is no need and the application can quit, now some who say they want to log ...
There is no need for any of this to go on at the level of the implementation, it is a restriction on the implementation to do so.
I can't stress enough how important it is that, used correctly, the impact of assertion during development is completely removed at runtime in production, completely removed, not by any voodoo, but by core software o+. That is of paramount importance for the ideal implementation, and we have that right now, there is no convincing reason to let it go.
Cheers
Joe
Am 22.10.2013 20:07 schrieb "Joe Watkins" [email protected]:
You can catch exceptions, and log them.
You can do that without impacting everything around you, you can do that, or whatever else you like.
You can do that handling when you have only a few toplevel scripts, like when you have a setup with a small number of toplevel controllers and almost no CLI stuff around. But due to the scoped nature of try/catch you cannot reasonably / painlessly do that when you have 270 toplevel web and CLI entry points that then each need such a try/catch block.
Also, there is the problem with catch (Exception) blocks, which you might easily dismiss as bad form, but which I'm sure are widespread in the field
- I certainly know they are in our codebase...
On the other hand, setup of an assertion-failed callback can easily go into an auto_prepend file, or into any other standard include (autoloader or something) you might have - exactly because it is something done on the global level instead of the scoped try/catch requirement. And IF you like the exception thing you can make that callback throw whatever you like - but you do not force that model on everybody.
Furthermore such an assertion-failed callback has exactly the same change of looking at backtraces, so touting that as a singular feature of the exception approach is not valid.
Finally, with the exception approach it is simply not true that it will completely go away in production - because these try/catch blocks will be present for any code that wants to handle the issue, and you cannot make those go away.
I'm all for an assert alternative that works with expressions instead of eval, and that completely goes away in the opcode (cache) when disabled in production.
best regards
Patrick
Quoted text · 7 lines
Am 22.10.2013 20:07 schrieb "Joe Watkins" [email protected]:
You can catch exceptions, and log them.
You can do that without impacting everything around you, you can do that, or whatever else you like.You can do that handling when you have only a few toplevel scripts, like when you have a setup with a small number of toplevel controllers and almost no CLI stuff around. But due to the scoped nature of try/catch you cannot reasonably / painlessly do that when you have 270 toplevel web and CLI entry points that then each need such a try/catch block.
Also, there is the problem with catch (Exception) blocks, which you might easily dismiss as bad form, but which I'm sure are widespread in the field
- I certainly know they are in our codebase...
On the other hand, setup of an assertion-failed callback can easily go into an auto_prepend file, or into any other standard include (autoloader or something) you might have - exactly because it is something done on the global level instead of the scoped try/catch requirement.
If you want to handle uncaught exceptions via auto_prepend_file you can use set_exception_handler(). It will register a global handler that is invoked on an uncaught exception. So you can have your functionality, if that's how you like to handle things, but you also have the option of fine-grained control of assertion failures by use of catch-blocks. One use case that I have repeatedly mentioned in the previous thread is that PHPUnit will want to catch the assertion failure but still continue running other tests.
Generally anything that uses a global handler (e.g. for assertion failures...) turns out to be a PITA when you try to combine multiple libraries which want different handlers. In the end you can't really use any such handlers in a portable library. I'd like assertions to be usable in libraries.
Thanks,
Nikita
Am 22.10.2013 20:41 schrieb "Nikita Popov" [email protected]:
If you want to handle uncaught exceptions via auto_prepend_file you can use
set_exception_handler(). It will register a global handler that is invoked on an uncaught exception.
Fair enough, thanks.
Generally anything that uses a global handler (e.g. for assertion failures...) turns out to be a PITA when you try to combine multiple libraries which want different handlers. In the end you can't really use any such handlers in a portable library. I'd like assertions to be usable in libraries.
How do you envision that to work in practise with the exception approach? Make every externally visible function and method in the library contain a suitable try/catch block?
best regards
Patrick
Quoted text · 12 lines
Am 22.10.2013 20:07 schrieb "Joe Watkins" [email protected]:
You can catch exceptions, and log them.
You can do that without impacting everything around you, you can do that, or whatever else you like.You can do that handling when you have only a few toplevel scripts, like when you have a setup with a small number of toplevel controllers and almost no CLI stuff around. But due to the scoped nature of try/catch you cannot reasonably / painlessly do that when you have 270 toplevel web and CLI entry points that then each need such a try/catch block.
Also, there is the problem with catch (Exception) blocks, which you might easily dismiss as bad form, but which I'm sure are widespread in the field
- I certainly know they are in our codebase...
On the other hand, setup of an assertion-failed callback can easily go into an auto_prepend file, or into any other standard include (autoloader or something) you might have - exactly because it is something done on the global level instead of the scoped try/catch requirement. And IF you like the exception thing you can make that callback throw whatever you like - but you do not force that model on everybody.
Furthermore such an assertion-failed callback has exactly the same change of looking at backtraces, so touting that as a singular feature of the exception approach is not valid.
Finally, with the exception approach it is simply not true that it will completely go away in production - because these try/catch blocks will be present for any code that wants to handle the issue, and you cannot make those go away.
I'm all for an assert alternative that works with expressions instead of eval, and that completely goes away in the opcode (cache) when disabled in production.
best regards
Patrick
I was pretty explicit: used properly.
We are going round in circles, discussing what assertion should be used for, again.
Production code should NOT have catch blocks everywhere to manage exceptions that will NEVER be thrown, obviously.
assertion is a debug and development feature, if you take code to production that catches exceptions that your configuration does not allow to be thrown then that's pretty silly.
assertion should be used during development, in development environments where it is enabled, by the time your code goes to production it should not suffer ExpectationExceptions and cannot anyway.
I think this thread and the RFC now contains enough information regarding exceptions, it is now covered ground.
Cheers
Joe
Quoted text · 8 lines
Evening Chaps,
Following on from discussion regarding assertion API in PHP, thefollowing RFC is now up for discussion:
https://wiki.php.net/rfc/expectations Please do point out any missing sections or information, so that itcan be clarified as quickly as possible.
I hope this conveys the idea a bit clearer to everyone ?Cheers
Joe
Evening,
Wanted to bring this up for vote, any objections ?
Cheers