php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #40122 Variable parsing eats up memory
Submitted: 2007-01-13 18:33 UTC Modified: 2007-06-15 01:21 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: spheroid@php.net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.2.1RC2 OS: Mac OS X 10.4.8
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: spheroid@php.net
New email:
PHP Version: OS:

 

 [2007-01-13 18:33 UTC] spheroid@php.net
Description:
------------
I'm not sure whether this is intended behaviour, but variable 
parsing inside strings seem to allocate memory, which is not 
freed until script has been executed.

Reproduce code:
---------------
$foo = 'value';
echo "first loop\n";

for ($i = 0; $i < 10; $i++) {
    $bar = "foo: $foo";
    echo memory_get_usage() . "\n";
}

echo "second loop\n";

for ($i = 0; $i < 10; $i++) {
    $bar = 'foo: ' . $foo;
    echo memory_get_usage() . "\n";
}

Expected result:
----------------
first loop
52280
52280
...
52280
52280
second loop
52516
52516
...
52516
52516

Actual result:
--------------
first loop
52280
52304
52328
52352
52376
52400
52424
52448
52472
52496
second loop
52516
52516
...
52516
52516


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-14 15:03 UTC] iliaa@php.net
The first loop creates temp vars and those are not freed until the script finished execution.
 [2007-01-14 22:12 UTC] spheroid@php.net
So if one should write a daemon or anything else with a bit 
longer life span and/or heavy I/O, she'd better avoid using 
parsed expressions inside strings?

Even though it's not a big deal, I still think it should be 
stated somewhere.
 [2007-06-15 01:21 UTC] gwynne@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 20:01:32 2025 UTC