문제

I'm trying to include a custom path to a certain file using php's set_include_path. Here's the code:

file.php

<?php
    $path = 'classes/';
    set_include_path(get_include_path() . PATH_SEPARATOR . $path);
    $obj = new MyClass();
    $obj->methodCall();
?>

Here's my root directory structure

www
|_webapp
       |_classes
               |_MyClass.php
       |_nbproject
       |_file.php

All I get when I execute the script is this error message: Fatal error: Class 'MyClass' not found in C:\wamp\www\webapp\file.php. I have tried including the file using require and it works but I have hit a wall with set_include_path. Does anybody know what I can do about this?

Thanks

도움이 되었습니까?

해결책

  1. You're adding a relative path to the global include path. Is that what you intended?
  2. You are possibly not including the file where class MyClass is defined. set_include_path() allows to omit the path in the require_once statement, not to omit the statement itself.

I have the impression that the tool you have in mind is class autoloader.

다른 팁

You choose include method like this format include 'path/filename.php'

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top