php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70006 cli - function with default arg = STDOUT crash output
Submitted: 2015-07-07 09:21 UTC Modified: 2015-07-07 10:39 UTC
From: simon dot minotto at gmail dot com Assigned: dmitry (profile)
Status: Closed Package: *General Issues
PHP Version: 7.0.0alpha2 OS: ubuntu 15.04 server
Private report: No CVE-ID: None
 [2015-07-07 09:21 UTC] simon dot minotto at gmail dot com
Description:
------------
using php in cli mode


With following code : 
<?php

function foo1($stream = STDOUT)
{
  //do nothing
}
echo "before\n";
foo1();
echo "after\n";


Excepted result : display
before
after


Result with php7 : 
before


Work fine with php 5.X


azureuser@php7test1:/mnt/eztv$ php -v
PHP 7.0.0alpha2 (cli) (built: Jul  7 2015 04:58:33) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies


'./configure' '--with-apxs2=/usr/bin/apxs' '--with-mysqli' '--enable-soap' '--enable-sockets' '--enable-sysvsem' '--with-xsl' '--enable-zip' '--enable-mbstring' '--with-curl' '--with-mcrypt' '--enable-ftp' '--with-gd' '--with-jpeg-dir=/usr/lib' '--enable-exif' '--with-openssl' '--enable-pcntl'

Test script:
---------------
<?php

function foo1($stream = STDOUT)
{
  //do nothing
}
echo "before\n";
foo1();
echo "after\n";


Excepted result : display
before
after

Expected result:
----------------
before
after

Actual result:
--------------
before

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-07 10:39 UTC] laruence@php.net
-Assigned To: +Assigned To: dmitry
 [2015-07-07 10:39 UTC] laruence@php.net
an quick fix is: 

diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c
index fc92494..1386c95 100644
--- a/Zend/zend_execute_API.c
+++ b/Zend/zend_execute_API.c
@@ -555,11 +555,9 @@ ZEND_API int zval_update_constant_ex(zval *p, zend_bool inline_change, zend_clas
 		zend_throw_error(zend_ce_error, "Cannot declare self-referencing constant '%s'", Z_STRVAL_P(p));
 		return FAILURE;
 	} else if (Z_TYPE_P(p) == IS_CONSTANT) {
-		int refcount;

 		SEPARATE_ZVAL_NOREF(p);
 		MARK_CONSTANT_VISITED(p);
-		refcount =  Z_REFCOUNTED_P(p) ? Z_REFCOUNT_P(p) : 1;
 		if (Z_CONST_FLAGS_P(p) & IS_CONSTANT_CLASS) {
 			ZEND_ASSERT(EG(current_execute_data));
 			if (inline_change) {
@@ -640,7 +638,7 @@ ZEND_API int zval_update_constant_ex(zval *p, zend_bool inline_change, zend_clas
 			zval_opt_copy_ctor(p);
 		}

-		if (Z_REFCOUNTED_P(p)) Z_SET_REFCOUNT_P(p, refcount);
+		/* if (Z_REFCOUNTED_P(p)) Z_SET_REFCOUNT_P(p, refcount); */
 	} else if (Z_TYPE_P(p) == IS_CONSTANT_AST) {
 		zval tmp;


however I am  not sure why SET_REFCOUNT_P here..
 [2015-07-07 11:26 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7af4e6d02d678b9e31c192e8adfc3bb9d6277f5a
Log: Fixed bug #70006 (cli - function with default arg = STDOUT crash output).
 [2015-07-07 11:26 UTC] laruence@php.net
-Status: Assigned +Status: Closed
 [2015-07-07 23:36 UTC] ab@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7af4e6d02d678b9e31c192e8adfc3bb9d6277f5a
Log: Fixed bug #70006 (cli - function with default arg = STDOUT crash output).
 [2016-07-20 11:38 UTC] davey@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7af4e6d02d678b9e31c192e8adfc3bb9d6277f5a
Log: Fixed bug #70006 (cli - function with default arg = STDOUT crash output).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC