douxiong3234 2014-09-23 16:38
浏览 77
已采纳

isset()中的未定义变量

Can be closed, lost the overview in my project and worked in a file, that has the same name and method. So no changes were made. It works now. Sorry for wasting your time. My mistake.

I have a static factory method in which I'm trying to get the classname of the parameter.

static function factory($row)
{
  if (is_null($classname)) {
    $classname=get_called_class();
  }

Error Output:

[Tue Sep 23 18:35:24.078345 2014] [:error] [pid 9971] [client 127.0.0.1:45702] PHP Notice: Undefined variable: classname in /var/www/dev/lib/class.base.php on line 9, referer:

> http://localhost/dev/app.php?action=do

When I try to set the $classname = null; before check it, there is also a undefined variable error. Same thing with isset($classname). What have i done wrong?

Here is another example, thhat doesn't work for me:

 class definetest{
 static function factory()
    {
      if (is_null($classname)) {
        $classname=get_called_class();
      }
      return $classname;
    }

}

$x = new definetest();

echo $x::factory();

It returns the classname, but I have an error in my apache log

  • 写回答

1条回答 默认 最新

  • dongyouzhi7218 2014-09-23 16:50
    关注
    static function factory($row)
    {
      if (isset($classname)) {
        $classname = get_called_class();
      }
    }
    

    If you use isset() before call to variable. It is not possible to show notice undefined variable.

    http://php.net/manual/en/function.isset.php isset — Determine if a variable is set and is not NULL

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM