Php 调用现有全局变量的记忆效应

Php 调用现有全局变量的记忆效应,php,variables,memory,global,Php,Variables,Memory,Global,在函数中调用现有的全局函数时是否存在内存影响 i、 e vs 与$someclass=newsomeclass()相比怎么样$someclass->otherclass=新建otherclass();函数foo($someclass){$someclass->otherclass->do_stuff();}可忽略,但确实存在。。。。但是,两个选项之间的实际逻辑也存在差异,因此您并不是将like与likeWell进行比较,因为我简化了这一问题,而是要重用现有(已加载)脚本的一部分。我想知道调用gl

在函数中调用现有的全局函数时是否存在内存影响

i、 e

vs


$someclass=newsomeclass()相比怎么样$someclass->otherclass=新建otherclass();函数foo($someclass){$someclass->otherclass->do_stuff();}
可忽略,但确实存在。。。。但是,两个选项之间的实际逻辑也存在差异,因此您并不是将like与likeWell进行比较,因为我简化了这一问题,而是要重用现有(已加载)脚本的一部分。我想知道调用global是否会创建某种实例,或者只是指向内存中已有的实例。在我的例子中,类已经作为全局类加载,我需要在函数中使用部分类。在第一个示例中,全局类指向内存中$someclass的原始实例,因此您正在处理已附加到$someclass的$otherclass。。。。对$otherclass的属性所做的任何更改都是对连接到$SomeClassic的$otherclass的唯一实例在第二个示例中,您正在创建一个新的$otherclass实例(占用内存),该实例是完全自包含的,与$someclass没有任何连接,并且它只存在于foo()的范围内,当foo()终止时,它将超出范围并被销毁,并再次释放内存
$someclass = new SomeClass();
$someclass->otherclass = new OtherClass();

function foo() {
    global $someclass;
    $someclass->otherclass->do_stuff();
}
$someclass = new SomeClass();
$someclass->otherclass = new OtherClass();

function foo() {
    $otherclass = new OtherClass();
    $otherclass->do_stuff();
}