php.net |  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
Votes:6
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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
29 + 36 = ?
Subscribe to this entry?

 
 [2004-09-14 05:44 UTC] portfolio at gmx dot co dot uk
Description:
------------
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());


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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:
http://www.sitepoint.com/forums/showthread.php?t=195284

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] tony2001@php.net
Reproducible only with HEAD & 5.0.x.
<?php
class A { 
    function A($arrayobj) { 
		var_dump($arrayobj);
    } 
} 

class B { 
} 

new A( new B() ); 
?>
 [2005-01-13 19:00 UTC] tony2001@php.net
No crash here, but I still got "UNKNOWN:0" as var_dump's output.
 [2005-03-09 21:53 UTC] sniper@php.net
# sapi/cli/php /home/jani/t.php 
UNKNOWN:0
/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] dmitry@php.net
Fixed in CVS HEAD and PHP_5_0.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 02:01:30 2024 UTC