How to use a PHP class from another file?

前端 未结 5 1672
庸人自扰
庸人自扰 2020-12-05 06:41

Let\'s say I\'ve got two files class.php and page.php

class.php



        
5条回答
  •  星月不相逢
    2020-12-05 06:48

    In this case, it appears that you've already included the file somewhere. But for class files, you should really "include" them using require_once to avoid that sort of thing; it won't include the file if it already has been. (And you should usually use require[_once], not include[_once], the difference being that require will cause a fatal error if the file doesn't exist, instead of just issuing a warning.)

提交回复
热议问题