duanjiang7505 2010-07-08 03:16
浏览 47
已采纳

在PHP对象中定义变量时出错

I am getting the following error in the following code:

Class primeField implements field {
    private $intmodulus = '';
    public function generator(){
        return ;
    }

    public function modulus(){
        return $this->$intmodulus;
    }
    public function __construct($modulus , $base=0) {
        if (is_resource($modulus) && get_resource_type($modulus) == "GMP integer"){
            $this->$intmodulus = $modulus;
        } else{
            $this->$intmodulus = gmp_init($modulus , $base); \\line 70
        }
    }
}
$a = new primeField(11);
$a->modulus();

Notice: Undefined variable: intmodulus in /Users/admin/PHP ECC/finitefield.php on line 70 Fatal error: Cannot access empty property in /Users/admin/PHP ECC/finitefield.php on line 70

Why

  • 写回答

2条回答 默认 最新

  • doutou7286 2010-07-08 03:17
    关注

    The syntax is

    $this->intmodulus 
    

    not $this->$intmodulus.

    You get an error saying "cannot access empty property" because $intmodulus is undefined and hence accessing it gives NULL. The NULL gets converted into an empty string when you attempt to use it as a property name.

    If the value of $intmodulus was the name of a valid property (e.g. if $intmodulus == "intmodulus"), you would be accessing the property with that name.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 经gamit解算的cors站数据再经globk网平差得到的坐标做形变分析
  • ¥15 GD32 SPI通信时我从机原样返回收到的数据怎么弄?
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题