Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
PHP Objects, Patterns, and Practice- P3: This book takes you beyond the PHP basics to the enterprise development practices used by professional programmers. Updated for PHP 5.3 with new sections on closures, namespaces, and continuous integration, this edition will teach you about object features such as abstract classes, reflection, interfaces, and error handling. You’ll also discover object tools to help you learn more about your classes, objects, and methods. | CHAPTER 5 OBJECT TOOLS Neither solution is ideal. By specifying paths in this much detail you freeze the library file in place. In using an absolute path you tie the library to a particular file system. Whenever you install the project on a new server all require statements will need changing to account for a new file path. By using a relative path you fix the relationship between the script s working directory and the library. This can make libraries hard to relocate on the filesystem without editing require statements and impractical to share among projects without making copies. In either case you lose the package idea in all the additional directories. Is it the business package or is it the projectlib business package In order to make included libraries work well in your code you need to decouple the invoking code from the library so that business User.php can be referenced from anywhere on a system. You can do this by putting the package in one of the directories to which the include_path directive refers. include_path is usually set in PHP s central configuration file php.ini. It defines a list of directories separated by colons on Unix-like systems and semicolons on Windows systems. include_path . usr local lib php-libraries If you re using Apache you can also set include_path in the server application s configuration file usually called httpd.conf or a per-directory Apache configuration file usually called .htaccess with this syntax php_value include_path value . usr local lib php-libraries Note .htaccess files are particularly useful in web space provided by some hosting companies which provide very limited access to the server environment. When you use a filesystem function such as fopen or require with a nonabsolute path that does not exist relative to the current working directory the directories in the include path are searched automatically beginning with the first in the list in the case of fopen you must include a flag in its argument list to .