Why can I register only one auto-load function for my spl_auto_register () function? Reply to discussion (solution)
Both of them can be registered successfully. Before you use the autoload function require, you must first determine whether it is a file.
Function _ autoload1 ($ className) {$ path = 'class /'. $ className. ". class. php "; if (is_file ($ path) require_once 'class /'. $ className. ". class. php ";} function _ autoload2 ($ phpFile) {$ path = $ phpFile. ". class. php "; echo $ path; if (is_file ($ path) require_once $ phpFile. ". class. php ";} spl_autoload_register ('_ autoload1'); spl_autoload_register ('_ autoload2'); $ page = new Page; $ person = new Person (); print_r ($ page); print_r ($ person );
Oh. Thank you. it turns out that we need to judge and load again, rather than let him fail to load, and then find the second function.