Re: [PHP] Best Practices for calling 'setup' classes that extend 'parent' classes?

2007-09-01 Thread Graham Anderson

Many thanks :)
This was very helpful.



On Aug 26, 2007, at 8:27 PM, Richard Lynch wrote:


Put all your classes into a single directory structure.

Use http://php.net/set_include_path (or php.ini or .htaccess) to
provide the FULL PATH to that directory.

PHP now knows where to start its search, and essentially prepends
that directory when it does an include.

Assume this directory structure:

/path/to/your/includes
   parent_class.php
   /child
  some_child_class.php

This works:
?php
set_include_path('/path/to/your/includes');
include 'parent_class.php';
include 'child/some_child_class.php';
?

Do not under any circumstances try to use './' or '../' in your
include statements.  You will only make yourself miserable in the long
run.

On Mon, August 20, 2007 1:52 pm, Graham Anderson wrote:

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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





--
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Best Practices for calling 'setup' classes that extend 'parent' classes?

2007-08-26 Thread Richard Lynch
Put all your classes into a single directory structure.

Use http://php.net/set_include_path (or php.ini or .htaccess) to
provide the FULL PATH to that directory.

PHP now knows where to start its search, and essentially prepends
that directory when it does an include.

Assume this directory structure:

/path/to/your/includes
   parent_class.php
   /child
  some_child_class.php

This works:
?php
set_include_path('/path/to/your/includes');
include 'parent_class.php';
include 'child/some_child_class.php';
?

Do not under any circumstances try to use './' or '../' in your
include statements.  You will only make yourself miserable in the long
run.

On Mon, August 20, 2007 1:52 pm, Graham Anderson wrote:
 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

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Best Practices for calling 'setup' classes that extend 'parent' classes?

2007-08-20 Thread Jay Blanchard
[snip]
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?
[/snip]

Have you considered autoloading? 

http://us2.php.net/autoload

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php