dtcuv8044 2013-10-09 16:01
浏览 45

too long

Hello im interested in understanding how variables are stored in php.

say i have two variables

$p = 1 + 1
$b = $p.

Does php save the result of the variable or does it save the procedure to run it? Why im wondering is if i store a function in it, does it store the return value or just copies the procedure.

Thank you!

Edit: I think it be best if i clarified what im talking about.

say:

    function foo($something)
{

    for loop
        {
       echo 'Something';

       }

   return $something;
}


$b = foo(5);

echo $b;

from what i encountered just assigning the value executes the function. And when i echo $b it also executes the function again.

  • 写回答

2条回答 默认 最新

  • doushi9780 2013-10-09 16:13
    关注

    So what you're wondering if you're assigning like this

    $a = function($arg){
        echo($arg);
    }
    
    $b = $a;
    

    will you have a duplicate of function in memory?

    Oops turns out i'm wrong. PHP uses copy-on-write mechanism, which makes both $b and $a use the same memory buffer UNLESS any of these variables are modified.

    Other possibility is you're wondering what happens when you do something like

    $a = 5; $b = 15;
    $c = sin($b)*sqrt($a);
    

    Then, only the value of these calculations will be stored in memory, nothing more.

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP