|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25227 Subclass of overloaded class loses pass-by-reference functionality.
Submitted: 2003-08-24 17:30 UTC Modified: 2003-08-24 21:51 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: chris at studentadvantage dot com Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: 4.3.2 OS: Linux 2.4.20-8smp
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 — but make sure to vote on the bug!
Your email address:
Solve the problem:
22 + 6 = ?
Subscribe to this entry?

 [2003-08-24 17:30 UTC] chris at studentadvantage dot com
When a class which is overloaded is included in another php file via 'require_once', 'require', etc., functions in classes which inherit from that class and that take references no longer seem to be getting references, rather they seem to be getting copies of the argument variables.

Here's my setup (from 'phpinfo()'):


PHP Version 4.3.2

System 	Linux charles 2.4.20-8smp #1 SMP Thu Mar 13 17:45:54 EST 2003 i686
Build Date 	Aug 20 2003 21:26:20
Configure Command 	'./configure' '--prefix=/opt/php' '--with-mysql' '--with-apxs=/opt/apache/bin/apxs'
Server API 	Apache
Virtual Directory Support 	disabled
Configuration File (php.ini) Path 	/opt/php/lib/php.ini
PHP API 	20020918
PHP Extension 	20020429
Zend Extension 	20021010
Debug Build 	no
Thread Safety 	disabled
Registered PHP Streams 	php, http, ftp

This program makes use of the Zend Scripting Language Engine:
Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies


Incidently, in my example code php doesn't complain if 'my_base_b::my_base_b()' is not defined, but it does give an error if 'my_base_a::my_base_a()' isn't defined. From what I read in the manual, it should complain because __call applies to constructors as well.

Reproduce code:
  class my_base_a {
    function my_base_a( ) { }
    function __call( $method, $params, &$return ) {
      return( false );


  class my_base_b {
    function my_base_b( ) { }
    function __call( $method, $params, &$return ) {
      return( false );

  class overload_a extends my_base_a {
    function modify_reference( &$ref ) {
      $ref = "Modified Reference";

  class overload_b extends my_base_b {
    function modify_reference( &$ref ) {
      $ref = "Modified Reference";

  $instance_a = new overload_a( );
  $instance_b = new overload_b( );
  $ref_a = $ref_b = "Unmodified Reference";

  print "Before: $ref_a, $ref_b<br>";
  $instance_a->modify_reference( $ref_a );
  $instance_b->modify_reference( $ref_b );
  print "After: $ref_a, $ref_b<br>";


Expected result:
Before: Unmodified Reference, Unmodified Reference
After: Modified Reference, Modified Reference

Actual result:
Before: Unmodified Reference, Unmodified Reference
After: Unmodified Reference, Modified Reference


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-08-24 21:41 UTC] chris at studentadvantage dot com
This is also an issue with php 4.3.3RC4, but not with 5.0.0b1
 [2003-08-24 21:51 UTC]
And it will stay as such with PHP 4.

 [2003-12-10 12:00 UTC] papercrane at reversefold dot com
Well, if PHP5 were stable, I wouldn't care, but...for now, it's very annoying.

Just a quick note for those having this problem. First, easiest way to fix it us to turn off overloading (for DB_DataObject, for instance, use 

For those who can't turn off overloading, use call-time pass-by-reference. Yes, it's deprecated, but it fixes the problem.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 15 22:01:28 2024 UTC