[日常] PHP设置 include_path 配置选项

动态设置php.ini中的include_path 配置选项:

两种方式
set_include_path($new_include_path)
ini_set('include_path',$new_include_path);
利用常量 PATH_SEPARATOR 可跨平台扩展 include path,可以把自己设置的path加在现有include_path的尾部

<?php
$path='/var/www/html';
//第一种
//set_include_path(get_include_path() . PATH_SEPARATOR . $path);

//第二种
ini_set('include_path', ini_get('include_path'). PATH_SEPARATOR.$path);
require 'test2.php';

var_dump($a);

在/var/www/html下建立test2.php

<?php
$a="hello world";

  

结果

  

原文地址:https://www.cnblogs.com/taoshihan/p/8515357.html