php.net |  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
Votes:1
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2003-08-24 17:30 UTC] chris at studentadvantage dot com
Description:
------------
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:
---------------
test_inc.php:
=================
<?php
  class my_base_a {
    function my_base_a( ) { }
    function __call( $method, $params, &$return ) {
      return( false );
    }
  };
  overload("my_base_a");
?>

test_main.php:
=================
<?php
  require_once('test_inc.php');

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

  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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] sniper@php.net
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 
define('DB_DATAOBJECT_NO_OVERLOAD', 0);

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

$obj->function(&$paramByRef);
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Dec 01 12:02:32 2020 UTC