php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75955 cli and php-fpm assert Behave Differently
Submitted: 2018-02-13 05:55 UTC Modified: 2021-08-29 04:22 UTC
From: xmlscript at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: Scripting Engine problem
PHP Version: 7.2.2 OS: Fedora 27
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: xmlscript at gmail dot com
New email:
PHP Version: OS:

 

 [2018-02-13 05:55 UTC] xmlscript at gmail dot com
Description:
------------
I want to get assertion code "assert(sleep(3))", 
but return "Assertion failed" or $exception->getMessage() === "".





===========================================================


php -r 'assert_options(ASSERT_ACTIVE,true);assert(sleep(3));'

PHP Warning:  assert(): **assert(sleep(3))** failed in Command line code on line 1
PHP Stack trace:
PHP   1. {main}() Command line code:0
PHP   2. assert() Command line code:1

Warning: assert(): **assert(sleep(3))** failed in Command line code on line 1

Call Stack:
    0.0001     406984   1. {main}() Command line code:0
    3.0001     407360   2. assert() Command line code:1


===========================================================


script file "test.php":
<?php
  echo PHP_SAPI,PHP_EOL;
  assert_options(ASSERT_ACTIVE,true);
  assert(sleep(3));
?>


===========================================================


lynx localhost/test.php

   fpm-fcgi

   ( ! ) Warning: assert(): **Assertion failed** in /path/to/test.php on line 4
   Call Stack
   # Time Memory Function Location
   1 0.0002 406992 {main}( ) .../exception.php:0
   2 3.0003 407368 assert ( ) .../exception.php:4


===========================================================


php test.php

cli
PHP Warning:  assert(): **Assertion failed** in /path/to/test.php on line 4
PHP Stack trace:
PHP   1. {main}() /path/to/test.php:0
PHP   2. assert() /path/to/test.php:4

Warning: assert(): Assertion failed in /path/to/test.php on line 4

Call Stack:
    0.0001     407896   1. {main}() /path/to/test.php:0
    3.0002     408304   2. assert() /path/to/test.php:4


===========================================================


php -r 'assert_options(ASSERT_ACTIVE,true);assert_options(ASSERT_EXCEPTION,true);assert(sleep(3));'
PHP Fatal error:  Uncaught AssertionError: **assert(sleep(3))** in Command line code:1
Stack trace:
#0 Command line code(1): assert(0, 'assert(sleep(3)...')
#1 {main}
  thrown in Command line code on line 1

Fatal error: Uncaught AssertionError: **assert(sleep(3))** in Command line code on line 1

AssertionError: assert(sleep(3)) in Command line code on line 1

Call Stack:
    0.0000     407384   1. {main}() Command line code:0
    3.0001     407760   2. assert() Command line code:1


===========================================================

script file "test_with_exception.php":
<?php
  echo PHP_SAPI,PHP_EOL;
  assert_options(ASSERT_ACTIVE,true);
  assert_options(ASSERT_EXCEPTION,true);
  assert(sleep(3));
?>


===========================================================


lynx localhost/test_with_exception.php

   fpm-fcgi

   ( ! ) Fatal error: Uncaught AssertionError in /path/to/test_with_exception.php on line 5
   ( ! ) AssertionError: in /path/to/test_with_exception.php on line 5
   Call Stack
   # Time Memory Function Location
   1 0.0001 407496 {main}( ) .../test_with_exception.php:0
   2 3.0002 407872 assert ( ) .../test_with_exception.php:5


===========================================================


php test_with_exception.php 
cli
PHP Fatal error:  Uncaught AssertionError in /path/to/test_with_exception.php:5
Stack trace:
#0 /path/to/test_with_exception.php(5): assert(0)
#1 {main}
  thrown in /path/to/test_with_exception.php on line 5

Fatal error: Uncaught AssertionError in /path/to/test_with_exception.php on line 5

AssertionError:  in /path/to/test_with_exception.php on line 5

Call Stack:
    0.0001     408408   1. {main}() /var/www/vhost/e/exception.php:0
    3.0002     408816   2. assert() /var/www/vhost/e/exception.php:5



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-06-22 17:03 UTC] nikic@php.net
I wasn't able to reproduce this issue against the built-in server. I also tried with and without opcache, as that's a typical cli/server difference.
 [2021-08-19 12:50 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-08-19 12:50 UTC] cmb@php.net
Does this still happen with any of the actively supported PHP
versions[1]?

[1] <https://www.php.net/supported-versions.php>
 [2021-08-29 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 08:01:28 2024 UTC