|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 07:00:01 2025 UTC |
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);