php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69363 eval()ed string literal is not interned on PHP7+OPcache
Submitted: 2015-04-03 00:58 UTC Modified: 2015-04-03 03:32 UTC
From: for-bugs at hnw dot jp Assigned:
Status: Not a bug Package: opcache
PHP Version: master-Git-2015-04-03 (Git) OS: any
Private report: No CVE-ID: None
 [2015-04-03 00:58 UTC] for-bugs at hnw dot jp
Description:
------------
On PHP7 without OPcache, eval('$bar="baz"') makes interned string. However, eval()ed string literal is dynamically allocated with OPcache enabled.

The interned string on PHP7 is not refcounted. So, string refcount(2) means non-interned.


Test script:
---------------
<?php
$foo="baz";
$eval_str='$bar="baz";';
eval($eval_str);
debug_zval_dump($foo);
debug_zval_dump($bar);


Expected result:
----------------
string(3) "baz" refcount(1)
string(3) "baz" refcount(1)

Actual result:
--------------
string(3) "baz" refcount(1)
string(3) "baz" refcount(2)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-03 02:39 UTC] laruence@php.net
-Status: Open +Status: Not a bug
 [2015-04-03 02:39 UTC] laruence@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

first of all, use or not use interned string, should not be cared about user land, it's a internal optimization, and also affects by intend string memory pool size .

and for opcache, opcache won't do any optimization for EVAL_CODES. so...this behavior is expected.

thanks
 [2015-04-03 03:32 UTC] for-bugs at hnw dot jp
-Summary: eval()ed string literal is not intened on PHP7+OPcache +Summary: eval()ed string literal is not interned on PHP7+OPcache
 [2015-04-03 03:32 UTC] for-bugs at hnw dot jp
Hmm. If you are right, enabling OPcache on PHP 7 causes little bit performance loss  and consuming more memories when we use eval().

$ php7 -d 'opcache.enable_cli=Off' /tmp/test-script.php
string(3) "baz" refcount(1)
string(3) "baz" refcount(1)
$ php7 -d 'opcache.enable_cli=On' /tmp/test-script.php
string(3) "baz" refcount(1)
string(3) "baz" refcount(2)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC