php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73303 Scope not inherited by eval in assert()
Submitted: 2016-10-12 15:16 UTC Modified: 2016-11-18 20:37 UTC
From: ildar dot aim at gmail dot com Assigned: dmitry
Status: Closed Package: *General Issues
PHP Version: 7.1.0RC3 OS: Linux
Private report: No CVE-ID:
 [2016-10-12 15:16 UTC] ildar dot aim at gmail dot com
Description:
------------
aim-server[~/tmp]$ /usr/bin/php --version                               
PHP 7.0.11 (cli) (built: Sep 16 2016 18:52:44) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Xdebug v2.4.1, Copyright (c) 2002-2016, by Derick Rethans
aim-server[~/tmp]$ /usr/bin/php test_class.php 
Success%                                                                                                                                                                                      aim-server[~/tmp]$ /opt/phpfarm/inst/php-7.1.0RC3/bin/php --version     
PHP 7.1.0RC3 (cli) (built: Oct 12 2016 16:13:20) ( NTS DEBUG )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies
aim-server[~/tmp]$ /opt/phpfarm/inst/php-7.1.0RC3/bin/php test_class.php 
PHP Warning:  assert(): Assertion "self::checkCacheKey(get_object_vars($this))" failed in /home/aim/tmp/test_class.php on line 7

Warning: assert(): Assertion "self::checkCacheKey(get_object_vars($this))" failed in /home/aim/tmp/test_class.php on line 7
PHP Fatal error:  Uncaught Error: Cannot access self:: when no class scope is active in /home/aim/tmp/test_class.php(7) : assert code:1
Stack trace:
#0 [internal function]: unknown()
#1 /home/aim/tmp/test_class.php(7): assert('self::checkCach...')
#2 /home/aim/tmp/test_class.php(17): Test->main()
#3 {main}
  thrown in /home/aim/tmp/test_class.php(7) : assert code on line 1

Fatal error: Uncaught Error: Cannot access self:: when no class scope is active in /home/aim/tmp/test_class.php(7) : assert code:1
Stack trace:
#0 [internal function]: unknown()
#1 /home/aim/tmp/test_class.php(7): assert('self::checkCach...')
#2 /home/aim/tmp/test_class.php(17): Test->main()
#3 {main}
  thrown in /home/aim/tmp/test_class.php(7) : assert code on line 1
aim-server[~/tmp]$ 


http://i.imgur.com/aG7kYps.png


I cannot find a description of this behavior in 
http://php.net/manual/en/migration71.incompatible.php

Test script:
---------------
aim-server[~/tmp]$ cat test_class.php 
<?php

class Test {
	public $prop;

	public function main(){
		assert('self::checkCacheKey(get_object_vars($this))');
		echo 'Success';
	}
	private static function checkCacheKey($obj_properties){
		return count($obj_properties) == 1;
	}
}

$obj = new Test();

$obj->main();


Expected result:
----------------
Success output 
or 
description in 
http://php.net/manual/en/migration71.incompatible.php

Actual result:
--------------
Fatal error: Uncaught Error: Cannot access self:: when no class scope is active in /home/aim/tmp/test_class.php(7) : assert code:1


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-12 21:29 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: dmitry
 [2016-10-12 21:29 UTC] cmb@php.net
It seems the behavior has changed as of commit 6499162f[1]. Is the
reported behavior intentional, Dmitry?

[1] <http://git.php.net/?p=php-src.git;a=commit;h=6499162ff0d8aa6e862d3e3cdd2288b87636b8a1>
 [2016-11-17 20:56 UTC] jmaguire at duo dot com
Still experiencing this in PHP7.1.0RC5.
 [2016-11-18 20:37 UTC] nikic@php.net
-Summary: Not documented Backward incompatible change related to assert +Summary: Scope not inherited by eval in assert() -Type: Documentation Problem +Type: Bug
 [2016-11-18 20:37 UTC] nikic@php.net
Regression due to EG(scope) removal. We should assign op_array->scope in zend_eval_stringl, like we do for ZEND_INCLUDE_OR_EVAL.
 [2016-11-18 20:42 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8bb39572704a480c929a9f4d52aa4bfd26fed1b2
Log: Fixed bug #73303
 [2016-11-18 20:42 UTC] nikic@php.net
-Status: Verified +Status: Closed
 [2016-11-22 13:14 UTC] krakjoe@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8bb39572704a480c929a9f4d52aa4bfd26fed1b2
Log: Fixed bug #73303
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Feb 28 14:01:40 2017 UTC