gpt4 book ai didi

php - set_include_path(get_include_path().PATH_SEPARATOR. 'phpseclib');

转载 作者:行者123 更新时间:2023-12-03 00:53:55 29 4
gpt4 key购买 nike

我偶然发现了两个我以前从未在 php 中使用过的函数

set_include_path();
get_include_path();

我目前正在寻求将 phpseclib 实现到我正在开发的项目中。因为我需要使用 SSH2 的 SFTP 类扩展,而这又需要 MathBigInteger 类......等等。

手册中提到了set_include_path():

"Sets the include_path configuration option for the duration of the script. "

这对于我的框架的其余部分意味着什么?它会设置“phpseclib”目录中的所有包含路径吗?

另外,我真的不明白:

set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');

我将 php sec 存储在我的文件系统中的自定义库目录中,get_include_path() 是否能够神奇地找到我的文件系统中的 phpseclib 目录?

正如你所看到的,我完全迷失在这里......有人可以为我提供一些启发吗?

PS/我只在应用程序的一个特定点需要这个库,因此只想在需要时包含它,目前我想将它包含在我的模型类的子级中。

最佳答案

首先你需要了解 include_path 是什么?配置设置的作用是:

Specifies a list of directories where the require, include, fopen(), file(), readfile() and file_get_contents() functions look for files. The format is like the system's PATH environment variable: a list of directories separated with a colon in Unix or semicolon in Windows.

PHP considers each entry in the include path separately when looking for files to include. It will check the first path, and if it doesn't find it, check the next path, until it either locates the included file or returns with a warning or an error. You may modify or set your include path at runtime using set_include_path().

结构

set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');

phpseclib 附加到当您请求包含具有上述功能之一的文件时搜索的目录列表。

由于 phpseclib 是相对路径,因此效果与指定 ./phpseclib 相同,即 PHP 将查找名为 phpseclib 的子目录 在进程的当前目录内。它不会神奇地确定库在文件系统中的位置;您的工作是将其放在可以找到的地方。

关于php - set_include_path(get_include_path().PATH_SEPARATOR. 'phpseclib');,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14295164/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com