gpt4 book ai didi

php - ini_set() 作用范围?

转载 作者:IT王子 更新时间:2023-10-29 00:07:58 24 4
gpt4 key购买 nike

我有 index.php 和几个级联包含的文件,类似这样。

index.php -> controller.php -> model.php -> view.php

model.php 我有一个函数使用 ini_set('memory_limit', '-1');

ini_set() 什么时候发布?更改设置过期了吗?

执行后index.php?还是view.php?还是model.php中的函数?

最佳答案

ini_set()global 对于脚本中发生的所有事情(不仅仅是当前文件:正在发生的整个执行线程),对于整个脚本要求;无论您从何处调用它,它都会始终影响此脚本的全局 设置。当您的脚本终止时,效果将过期 - 例如通过exitdie,或者跑到index.php的末尾。

不会影响任何其他同时运行的脚本(需要自己调用ini_set),也不会持久化到后面的请求中(如果需要持久化设置,需要编辑 php.ini).

请注意 documentation says the same thing :

Sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.


编辑:由于显然不清楚:您使用 ini_set 更改的值将对整个脚本有效。当前执行在哪里并不重要(在什么文件中,在什么类中,在什么函数中);设置将是相同的,无处不在。它将保持不变,直到您再次更改它,或者直到整个脚本终止。 (不是当前文件,不是当前函数;整个脚本)

关于php - ini_set() 作用范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6490955/

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