note 38737 deleted from function.require-once by didou
| From: | didou@php.net | Date: | Mon, 05 Jan 2004 13:45:06 +0000 |
| Subject: | note 38737 deleted from function.require-once by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-62944@lists.php.net to get a copy of this message | ||
Note Submitter: Anders.Martensson@vondi.no-ip.com
----
In the following example require_once does not work (PHP version 4.3.3):
Class definition:
<?php
class aname
{
function aname()
{
require_once('anotherclass.php');
$anotherclassobj=new anotherclass;
}
}
?>
Main page:
<?php
require_once('anotherclass.php');
include('anameclass.php');
$anotherclassobj=new anotherclass;
$anameobj=new aname;
?>
The error I get is when I create a new aname object in the main page. Error is "cannot
redeclare class anotherclass in anotherclass.php". You have to use class_exists in the
definition of aname class to get past this problem.
I.E:
<?php
class aname
{
function aname()
{
if(!class_exists('anotherclass'))
{
require_once('anotherclass.php');
}
$anotherclassobj=new anotherclass;
}
}
?>
I hope this helps someone. :)
Kind Regards
Anders Mårtensson