php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35360 cat | php -a has different behaviour to php -f
Submitted: 2005-11-24 09:53 UTC Modified: 2005-11-28 03:45 UTC
From: phpbug-david at tulloh dot id dot au Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.1.0 OS: Debian Linux
Private report: No CVE-ID: None
 [2005-11-24 09:53 UTC] phpbug-david at tulloh dot id dot au
Description:
------------
Actually using php 5.1.0, final release.

PHP does not seem to handle exceptions correctly when called with php -a.

I have two test cases that demonstrate the problem with slightly different output.
The tests were run with:
php -n -f test1.php
cat test1.php | php -n -a

Reproduce code:
---------------
test1.php:
<?php
class TC
{
        public function __construct() {}
        public function __set($name, $value) {
                throw new Exception();
        }
}
$tr = new TC();
$tr->first =4;
$tr2= new TC();
var_dump($tr2);
$tr2->first=9;
?>

test2.php:
<?php
class TC
{
        public function __construct() {}
        public function afunc() {
                throw new Exception();
        }
}
$tr = new TC();
$tr->afunc();
$tr2 = new TC();
var_dump($tr2);
$tr2->afunc();
?>

Expected result:
----------------
The php -n -f command produces the expected results:

Fatal error: Uncaught exception 'Exception' in test1.php:5
Stack trace:
#0 test1.php(10): TC::__set('first', 4)
#1 {main}
  thrown in test1.php on line 6

Fatal error: Uncaught exception 'Exception' in test2.php:6
Stack trace:
#0 test2.php(11): TC->afunc()
#1 {main}
  thrown in test2.php on line 6


Actual result:
--------------
cat test1.php | php -n -a produces:

Interactive mode enabled

NULL

Fatal error: Invalid opcode 137/1/8. in - on line 14


and test2:

Interactive mode enabled

NULL

Fatal error: Call to a member function afunc() on a non-object in /home/lod/ecouch/full/objects/- on line 14

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-24 09:57 UTC] phpbug-david at tulloh dot id dot au
Removing the __construct line will cause the script to Segfault when called with php -n -a.

Here is a backtrace for test1 with the construct line removed:

#0  0x0819a103 in zend_do_fcall_common_helper_SPEC (execute_data=0xbfffc220, tsrm_ls=0x8290018)
    at zend_vm_execute.h:131
#1  0x08199f7c in execute (op_array=0x833b308, tsrm_ls=0x8290018) at zend_vm_execute.h:88
#2  0x0816207b in execute_new_code (tsrm_ls=0x8290018)
    at /home/lod/Downloads/php-5.1.0/Zend/zend_execute_API.c:1151
#3  0x0814520f in zendparse (tsrm_ls=0x8290018) at Zend/zend_language_parser.c:2732
#4  0x0814a645 in compile_file (file_handle=0x2, type=2, tsrm_ls=0x8290018)
    at Zend/zend_language_scanner.c:3168
#5  0x0816db91 in zend_execute_scripts (type=8, tsrm_ls=0x8290018, retval=0x0, file_count=3)
    at /home/lod/Downloads/php-5.1.0/Zend/zend.c:1082
#6  0x08124aa4 in php_execute_script (primary_file=0xbffffab0, tsrm_ls=0x8290018)
    at /home/lod/Downloads/php-5.1.0/main/main.c:1704
#7  0x081fd0bc in main (argc=3, argv=0xbffffb74)
    at /home/lod/Downloads/php-5.1.0/sapi/cli/php_cli.c:1039



Also my configure line:
./configure \
        '--disable-all' \
        '--disable-cgi' \
        '--enable-cli' \
        '--enable-debug' \
        '--with-apxs2=/usr/bin/apxs2' \
        '--with-pear' \
        '--prefix=/usr'\
        '--with-config-file-path=/etc/php5' \
        '--enable-libxml' \
        '--enable-xml' \
        '--enable-spl' \
        '--with-layout=GNU' \
        '--with-exec-dir=/usr/lib/php5/libexec' \
        '--with-regex=php' \
        '--with-libxml-dir=/usr' \
        '--with-zlib' \
        '--with-zlib-dir=/usr' \
        '--with-libedit=shared,/usr' \
        '--with-mime-magic=/usr/share/php5/magic.mime' \
        '--with-pcre-regex=shared,/usr' \
        '--with-pgsql=shared,/usr' \
        '--with-tidy=shared,/usr'

The -n flag should have removed all the shared modules.
I'm afraid I won't be able to provide any more feedback for several days.
 [2005-11-24 10:12 UTC] sniper@php.net
Dmitry, can you check this out please?
 [2005-11-24 12:33 UTC] dmitry@php.net
Fixed in CVS HEAD, PHP_5_1 and PHP_5_0.
 [2005-11-28 03:45 UTC] phpbug-david at tulloh dot id dot au
confirmed fixed in 5.1.1
Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 10:01:30 2024 UTC