dongtiao2105 2010-01-05 00:45
浏览 55

PHP函数返回一个引用变量

I'm trying to write a function that will return a reference to a PDO object. The reason for wanting a reference is if, for some reason, the PDO object gets called twice in one page load, it will just return the same object rather than initializing a new one. This isn't silly, is it? :/

function &getPDO()
{
   var $pdo;

   if (!$pdo)
   {
      $pdo = new PDO...

      return $pdo;
   }
   else
   {
      return &pdo;
   }
}

Something like that

  • 写回答

4条回答 默认 最新

  • dongpang9573 2010-01-05 00:47
    关注

    To make a reference to a variable $foo, do this:

    $bar =& $foo;
    

    Then return $bar.

    评论

报告相同问题?

悬赏问题

  • ¥20 画CAD几张图片内容如下1111111111111111111111111111111111111111111
  • ¥15 基于python的电影系统推荐
  • ¥20 springmvc重定向和返回json
  • ¥15 数学建模——参会安排怎么做
  • ¥15 电脑键盘实现触摸功能
  • ¥25 matlab无法将表达式转换为双数组怎么解决?
  • ¥15 单片机汇编语言相关程序
  • ¥20 家用射频美容仪技术规格
  • ¥15 大家帮我看看为什么错了
  • ¥15 unity互动琴弦抖动效果