php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57537 cannot declare attributes in class that extends class from another file
Submitted: 2007-02-20 11:53 UTC Modified: 2009-12-04 12:02 UTC
From: php at sea-incorporated dot com Assigned: val (profile)
Status: Closed Package: bcompiler (PECL)
PHP Version: 5.2.1 OS: FreeBSD
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at sea-incorporated dot com
New email:
PHP Version: OS:

 

 [2007-02-20 11:53 UTC] php at sea-incorporated dot com
Description:
------------
If you declare class A with a member variable in one file, then require_once() that file from another file where you declare class B as extending class A, you cannot declare a member variable in class B.  Note this bug only occurs when classes are in two separate files.

Compile files below with normal bcompiler_write_header(), bcompiler_write_file(), bcompiler_write_footer().

Symptom is PHP trying/failing to allocate ~1.5G of memory
and is reported on the line where class B extends class A.

Reproduce code:
---------------
File a.php:

<?php
class A {
   var $attr_a;
}
?>

File b.php:

<?php
require_once('a.php');
class B extends class A {
   var $attr_b;
}
?>

Expected result:
----------------
(no output expected)

Actual result:
--------------
Fatal error: Allowed memory size of 134217728 bytes exhausted at /tmp/ports/usr/ports/lang/php5/work/php-5.2.1/Zend/zend_compile.c:46 (tried to allocate 1515870811 bytes) in b.php on line 3


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-20 11:56 UTC] php at sea-incorporated dot com
Whoops... line 3 in file b.php should obviously be:
class B extends A {
and not:
class B extends class A {
as shown in the original submission.
 [2007-07-04 01:38 UTC] zobo at scene-si dot org
Hi..
I have the same problem, but as I follow the rule "hack first, ask questions later". I also have a solution (almost).

It seems that the doc_something and doc_something_len are uninitialized and that usually results in trying to allocate something like 124365434 bytes of memory when performing the inheritance.

I'll post a patch as soon as I can.

Btw: Is there a CVS for this project? I could imagine this kind of thing has been fixed long ago? Is the project maintained? (Alternatives?) Should I get the latest code from APC?
Thanks...
 [2007-07-04 01:40 UTC] alan at akbkhome dot com
see: cvs.php.net/pecl/bcompiler

Patches do help.
- there is some life in the project, val does alot of work on it every so often.
 [2007-07-05 04:37 UTC] zobo at scene-si dot org
Ok.. I'll look at CVS...
This is the fix..
The behavior only occurs on PHP5 (new structures...) and there was something uninitialized...
It would be really nice if at least this were released asap, as people will thing it doesn't work for php5...

Great work!


diff -uNr bcompiler-0.8-orig/bcompiler.c bcompiler-0.8-zobo/bcompiler.c
--- bcompiler-0.8-orig/bcompiler.c      2006-10-04 10:45:28.000000000 +0200
+++ bcompiler-0.8-zobo/bcompiler.c      2007-07-05 10:32:43.000000000 +0200
@@ -2687,6 +2687,8 @@
 void apc_create_zend_property_info(zend_property_info** zf TSRMLS_DC)
 {
        *zf = (zend_property_info*) emalloc(sizeof(zend_property_info));
+       memset(*zf, 0, sizeof(zend_property_info));
        apc_deserialize_zend_property_info(*zf TSRMLS_CC);
 }
 [2009-12-04 12:02 UTC] val@php.net
Release 0.9.1 has this bug fixed.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Dec 01 10:03:34 2021 UTC