1

Just a quick question really.

I am re-writing a site and I am converting it all to OOP and putting it all into templates.

I have multiple classes, but I want to extend one of them from a separate file/class.

Do I have to require_once() the parent class to extend it?

I'm guessing you do but I just wanted to make sure.

Thanks in advance!

4 Answers 4

5

Yes, or you can look at http://www.php.net/spl_autoload_register to write a simple autoloader.

Sign up to request clarification or add additional context in comments.

Comments

4

Of course NO.
Don't write code in PHP4-style.
Use autoloading, namespaces and naming standards: PSR-0

Comments

2

Nomally it's neat to define an autoloader when you want to include a bunch of classes from a bunch of different files such as:

function __autoload( $className ) {
    $className = str_replace( "..", "", $className );
    require_once( "classes/$className.php" );
    // echo "Loaded classes/$className.php";
}

And then load whatever class name you have, i.e.:

$member = new Member();

1 Comment

That is exactly the info I was looking for, between yourself and Joe that is very useful :) Thanks again guys!
2

Yes, you have, otherwise the class wouldn't "exist" to PHP. Also, if you have some sensible naming convention, you should have a look into autoloading.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.