php如何执行分配给变量的函数?

sai*_*int 6 php

好吧,我真的不知道怎么说这个问题,但让我解释一下.

假设我有一个变量:

$file = dirname(__FILE__);
Run Code Online (Sandbox Code Playgroud)

如果我分配$file给另一个变量会怎么样?

$anotherVariable = $file;
Run Code Online (Sandbox Code Playgroud)

dirname每次分配时都会执行该功能吗?

谢谢你的帮助.

Ada*_*ght 12

不可以.PHP是必不可少的,因此评估赋值表达式的右侧,并将结果存储在"左侧"(在简单且几乎无处不在的情况下,左侧命名的变量).

$a = $b;  // Find the value of $b, and copy it into the value of $a
$a = 5 + 2; // Evaulate 5 + 2 to get 7, and store this in $a
$a = funcName(); // Evaluate funcName, which is equivalent to executing the code and obtaining the return value. Copy this value into $a
Run Code Online (Sandbox Code Playgroud)

当你通过引用分配($ a =&$ b)时,这会变得有点复杂,但我们现在不必担心这一点.