|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30080 Passing array or non array of objects
Submitted: 2004-09-14 05:44 UTC Modified: 2005-06-03 17:03 UTC
Avg. Score:4.0 ± 1.0
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:1 (25.0%)
From: portfolio at gmx dot co dot uk Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2005-03-09 OS: *
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: portfolio at gmx dot co dot uk
New email:
PHP Version: OS:


 [2004-09-14 05:44 UTC] portfolio at gmx dot co dot uk
When I pass an array of objects without first initializing them with a variable, I get either a crash or error (Depends on whether if its array).

Reproduce code:
class A { 
    function A($arrayobj) { 
        while(list($key, $value) = each($arrayobj)) { 
            echo $value->spit(); 

class B { 
    function spit() { 
        return 'This is class B' . "\n"; 

class C { 
    function spit() { 
        return 'This is class C' . "\n"; 

new A( array( new B(), new C())); 

Expected result:
I got this error:

This is class B 
Fatal error: Call to a member function spit() on a non-object in

If I do:

$b = new B; $c = new C; 
new A( array($b, $c)); 

It works but very long winded.

Another bug here causes Apache to crash:

class A 
    function A($value) { 
       echo $value->spit(); 

class B { 
    function spit() { 
        return 'This is class B' . "\n"; 

new A( new B());


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-14 17:55 UTC] php30080 at pointbeing dot net
Behaviour is reproducible using 5.00 on Fedora Linux (core 2).

There's an ongoing discussion of the behaviour on the Sitepoint forums here:

By way of a summary, it appears that the problems occur when constructing a number of new objects without assigning them anywhere, so:

new A( array( new B(), new C()));  // fails

$a = new A( array( new B(), new C()));  // fine

some_function( array( new B(), new C())); //fine
 [2004-11-28 16:35 UTC]
Reproducible only with HEAD & 5.0.x.
class A { 
    function A($arrayobj) { 

class B { 

new A( new B() ); 
 [2005-01-13 19:00 UTC]
No crash here, but I still got "UNKNOWN:0" as var_dump's output.
 [2005-03-09 21:53 UTC]
# sapi/cli/php /home/jani/t.php 
/usr/src/php/php5/Zend/zend_vm_execute.h(370) :  Freeing 0x092FE03C (16 bytes), script=/home/jani/t.php
=== Total 1 memory leaks detected ===

 [2005-06-03 17:03 UTC]
Fixed in CVS HEAD and PHP_5_0.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Apr 16 18:01:23 2021 UTC