php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44636 class_exists() memory leak
Submitted: 2008-04-04 10:09 UTC Modified: 2008-04-15 07:27 UTC
From: bigtree at 29a dot nl Assigned:
Status: Closed Package: Class/Object related
PHP Version: 5.2.5 OS: FreeBSD 6.1-RELEASE-p10
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bigtree at 29a dot nl
New email:
PHP Version: OS:

 

 [2008-04-04 10:09 UTC] bigtree at 29a dot nl
Description:
------------
When implicitely casting class_exists() to a boolean, a memory leak occurs. It does not matter if the given class exists or not.

Reproduce code:
---------------
for ($i = 1; $i < 100; $i++) {

    if (class_exists('foo')) { }
    echo memory_get_usage() . "\n";	
	
}


Expected result:
----------------
A constant amount of memory (at least after the first iteratation)

Actual result:
--------------
A growing amount of used memory.

A workaround can be:

if ((boolean)class_exists('foo')) { }

or

$foo = class_exists('foo');
if ($foo) {} 

in these cases the memory leak does not occur

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-12 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2008-04-15 07:09 UTC] bigtree at 29a dot nl
Tried this on a different machine with same OS + PHP version. The bug does not occur there. I assume a rebuild will help.
 [2008-04-15 07:27 UTC] bigtree at 29a dot nl
Disabling the Zend Optimizer actually solved the problem.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 00:01:35 2025 UTC