Best Practices for calling 'setup' classes that extend 'parent' classes?
| From: | Graham Anderson | Date: | Mon, 20 Aug 2007 18:52:19 +0000 |
| Subject: | Best Practices for calling 'setup' classes that extend 'parent' classes? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-261060@lists.php.net to get a copy of this message | ||
What is the best practice for correctly targeting 'include' paths when using Initialization/Setup classes that extend Parent classes?
In my extend_parent_class.php file, I have to provide an incorrect relative path. Apparently, the path (that does work) is relative to php file that calls the initialization/setup class (call_the_extend_parent_class.php). Is there a less confusing way to correctly target include paths when creating initialization classes?
Should I be using absolute paths instead?
many thanks in advance
extend_parent_class.php:
include_once('./path/to/parent_class.php'); # Works with 'incorrect' relative path
//include_once('../path/to/parent_class.php'); # Fatal Error with 'correct' relative path
class Initialize_Parent_Class extends Parent_Class {
function Initialize_Parent_Class()
{
$this->Parent_Class();
echo "This was successful and does not result in a fatal 'class not found' error";
}
}
Call the initialization class.
call_the_extend_parent_class.php:
<?php
require('./includes/extend_parent_class.php'); # initialize Parent Class
$parent_class = new Initialize_Parent_Class();
// prints 'This was successful and does not result in a fatal 'class not found' error'
?>
File structure:
php
++call_the_extend_parent_class.php
++ includes directory
++++ extend_parent_class.php
++ classes directory
++++ parent_class.php