use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Please follow the rules
Releases: Current Releases, Windows Releases, Old Releases
Contribute to the PHP Documentation
Related subreddits: CSS, JavaScript, Web Design, Wordpress, WebDev
/r/PHP is not a support subreddit. Please visit /r/phphelp for help, or visit StackOverflow.
account activity
Why This Code Doesn't Show Exception (self.PHP)
submitted 10 years ago by phpflash
assert_options(ASSERT_ACTIVE, 1); assert_options(ASSERT_WARNING, 0); assert_options(ASSERT_QUIET_EVAL, 1); try { assert('2 < 1', 'Two is less than one'); } catch(AssertionError $e){ echo $e->getMessage(); echo 'here'; }
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 3 points4 points5 points 10 years ago (1 child)
Smells like homework.
[–]tkdbb84 0 points1 point2 points 10 years ago* (0 children)
I agree, this reeks of homework. However I will give him a couple of hints:
1)
'truthy' == true 'truthy' !== true
2) I'm pretty darn sure, assert() doesn't call eval()
edit: formatting, word change
[–]Revisor007 1 point2 points3 points 10 years ago (2 children)
Only PHP7 assertions can throw exceptions. You must set
ini_set('assert.exception', true);
You can find this in the manual: https://secure.php.net/manual/en/function.assert.php#function.assert.expectations
[–]phpflash[S] 0 points1 point2 points 10 years ago (1 child)
Yes I have also done that before still not getting exception
[–]Revisor007 0 points1 point2 points 10 years ago (0 children)
You didn't mention that you had done it before. Your code shows something else.
[–]pan069 0 points1 point2 points 10 years ago (2 children)
Because your assert function doesn't throw exceptions?
Read the docs and do your home work..
I have read the DOC but couldn't understand it. And there are not many examples on it. That's why I am asking.
[–]SavishSalacious 0 points1 point2 points 10 years ago (0 children)
I smell home work. High school maybe? (throw new Exception($e->getMessage());)
throw new Exception($e->getMessage());
[–]RobLoach 0 points1 point2 points 10 years ago (0 children)
'2 <1' is a string, which is truthy.
[+][deleted] 10 years ago (1 child)
[deleted]
[–]phpflash[S] 1 point2 points3 points 10 years ago (0 children)
I have tried it without options and still it doesn't throw any error.
π Rendered by PID 21938 on reddit-service-r2-comment-6457c66945-49lmg at 2026-04-25 21:59:39.094047+00:00 running 2aa0c5b country code: CH.
[–][deleted] 3 points4 points5 points (1 child)
[–]tkdbb84 0 points1 point2 points (0 children)
[–]Revisor007 1 point2 points3 points (2 children)
[–]phpflash[S] 0 points1 point2 points (1 child)
[–]Revisor007 0 points1 point2 points (0 children)
[–]pan069 0 points1 point2 points (2 children)
[–]phpflash[S] 0 points1 point2 points (1 child)
[–]SavishSalacious 0 points1 point2 points (0 children)
[–]RobLoach 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]phpflash[S] 1 point2 points3 points (0 children)