php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40679 problems with $class_name in __autoload
Submitted: 2007-03-01 10:03 UTC Modified: 2007-03-03 22:06 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: habeck at gmx dot de Assigned: helly (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: 5.2.1 OS: *
Private report: No CVE-ID: None
 [2007-03-01 10:03 UTC] habeck at gmx dot de
Description:
------------
I have also problems with __autoload on windows 2003 apache 2.2.4/php 5.2.1. The following function does not what it did in apache 2.0.x and earlier versions of php:

function __autoload($class_name) {
	require_once(KH_APP_LIBPATH.$class_name.'.php');
}

The errormessage:

PHP Fatal error:  require_once(): Failed opening required 'D:/xxx/xxx/.php' (include_path='./;D:/xxx/xxx/') in D:\xxx\xxx\index.php on line 6

So there seems to be no value for $classname.

Reproduce code:
---------------
function __autoload($class_name) {
	require_once(KH_APP_LIBPATH.$class_name.'.php');
}


Expected result:
----------------
Opening the classfile: D:/xxx/xxx/blah.php

Actual result:
--------------
PHP Fatal error:  require_once(): Failed opening required 'D:/xxx/xxx/.php' (include_path='./;D:/xxx/xxx/') in D:\xxx\xxx\index.php on line 6


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-01 10:56 UTC] habeck at gmx dot de
same error on windows 2003 with apache 2.0.59
 [2007-03-01 11:08 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2007-03-03 05:08 UTC] habeck at gmx dot de
There are three files:

autoload-file (test.php):

<?php

function __autoload($class_name)
{
	require_once($class_name.'.php');
}

$txt = 'config.xml';

$o = new blah($txt);
$o->sayHallo();

?>


class-file (blah.php):

<?php

class blah {

	private $var;
	
	function __construct($var = '')
	{
		$this->var = simplexml_load_file($var, '', LIBXML_NOCDATA+LIBXML_COMPACT);
	}

	function sayHallo()  
	{  
		print('hallo world!');
	}

}

?>


xml-file (config.xml):

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<config>
<templates>
</templates>
</config>


error comment:

I have tried to find out where the error occurs and it seems that the empty second parameter in the function call "simplexml_load_file" overrides the variable value of $class_name.
 [2007-03-03 11:21 UTC] helly@php.net
The crash is not good but you should really read the documentation.

I'll fix the crash. Not your problem though.
 [2007-03-03 13:39 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Ok read this again. It is all perfectly fine and there is no crash. There is only an E_ERROR. That is because you explicitly set class name to \'\' - RTFM.
 [2007-03-03 22:06 UTC] habeck at gmx dot de
Sorry for this "bug report". You are right for version 5.2.1. In earlier versions it automatically seems to replace the empty string (second argument) with "SimpleXMLElement" and everything works fine. Now you explicitly have to fill in the default classname "SimpleXMLElement". So thanks for the help.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 23:01:30 2024 UTC