i want to ask how about to include file inside PHP class itself? <?php $db_host = 'localhost'; $db_usr = 'test'; $db_pwd = 'testpass'; $db_db = 'test'; include('function/important.php') ?> Code (markup): is this already correct way?
It's absolutely fine but I'd be looking at why it's a separate file These would be ok: including a simple file with database info setting up a templating or "view" functionality for MVC to get a new class that can then be instantiated And not ok: adding new functionality to the class you're already in
First use "require" and not include, then use full path like: require('/home/username/public_html/function/important.php');
The OP's question is an XY Problem, therefore the answers given to it are not the right answers for the real problem. You do not hard code dependencies in a class. You use Dependency Injection. The answers to Op's question would create what is known as Tight Coupling which you do not want to do.
Everyone is over thinking this... He doesn't have a created class. He's misusing the term class. He wants to know how to include a PHP script from another PHP script. Using "include" and "require" would be correct.