2013-05-13 114 views
-1

我不能为我的生活弄清楚为什么被抛出这个错误...我提供一个有效的数组,它仅仅是一个基本的循环PHP无效参数提供

PHP

class stats { 

    private $resirictedChars = array('@', '(', ')', '"', '<', '>', ',', '?', ':', ';', '[', ']', '{', '}'); 

    function __construct() {} 

    public function generateStats ($text) { 

     foreach ($this->restrictedChars as $char) { 

      $text = str_replace($char, '', strtolower($text)); 

     } 

     echo $text; 

    } 
} 

$run = stats::generateStats('hello.'); 

错误

Warning: Invalid argument supplied for foreach() 
+4

检查名称,它们不匹配:'$ resirictedChars'!=='$ restrictedChars' – 2013-05-13 18:51:36

+1

您在初始化数组时名称错误。 – andrewsi 2013-05-13 18:51:44

+0

它总是最愚蠢的东西......谢谢你haha – user2359318 2013-05-13 18:52:19

回答

0

您输入了错误的变量名。

变化private $resirictedChars = array...

private $restrictedChars = array...

1

错字在变量名,$resirictedChars V/S $restrictedChars