Ben örnek bir php kodu ile bu hatayı taklit etmeye çalışıyorum ama başarılı olamamıştır. Herhangi bir yardım büyük olurdu.
"Bir dizi olarak mahsup dize kullanamazsınız"
... Bu oluşturulamamasını:
$foo = 'bar';
$foo[0] = 'bar';
... Bu oluşturulamamasını:
$foo = 'bar';
if (is_array($foo['bar']))
echo 'bar-array';
if (is_array($foo['bar']['foo']))
echo 'bar-foo-array';
if (is_array($foo['bar']['foo']['bar']))
echo 'bar-foo-bar-array';
(Gönderen bugs.php.net aslında)
so why doesn't the error appear in the first if condition even though it is a string.
PHP bir çok bağışlayıcı bir programlama dili olduğu için, ben tahmin ediyorum. Ben oluyor düşünüyorum ne kodu ile göstermek gerekir:
$foo = 'bar';
// $foo is now equal to "bar"
$foo['bar'] = 'foo';
// $foo['bar'] doesn't exists - use first index instead (0)
// $foo['bar'] is equal to using $foo[0]
// $foo['bar'] points to a character so the string "foo" won't fit
// $foo['bar'] will instead be set to the first index
// of the string/array "foo", i.e 'f'
echo $foo['bar'];
// output will be "f"
echo $foo;
// output will be "far"
echo $foo['bar']['bar'];
// $foo['bar'][0] is equal calling to $foo['bar']['bar']
// $foo['bar'] points to a character
// characters can not be represented as an array,
// so we cannot reach anything at position 0 of a character
// --> fatal error
Ben benzer bir sorun kavga, böylece durumda kullanışlı burada belgeleyen edildi.
Bir __ get () yönteminde I (basitleştirilmiş örnek) olduğu gibi, bir özellik olarak verilen argümanını kullanarak edildi:
function __get($prop) {
return $this->$prop;
}
Yani ... $ Obj-> fred sınıfının Özel / korumalı fred özelliğine erişmek istiyorum.
Ben bu özelliği içinde bir dizi yapısını başvurmak için gerekli zaman Dize dizi hata olarak ofset kullanmak değil miyim üretilen bulundu. İşte ben yanlış yaptım ve nasıl bunu düzeltmek için ne:
function __get($prop) {
// this is wrong, generates the error
return $this->$prop['some key'][0];
// this is correct
$ref = & $this->$prop;
return $prop['some key'][0];
}
Açıklama: Biz bir yerde KQUEUE $ pervane için gerekir ise yanlış örnekte, php, ['some key']
$prop
(bir dize) için bir anahtar olarak yorumluyor. Perl Eğer {} ile belirterek bu yapabilirdi ama ben bu PHP mümkün olduğunu sanmıyorum.
I just want to explain my solving for the same problem.
(Verilen aynı hata) önce benim kodu:
$arr2= ""; // this is the problem and solve by replace this $arr2 = array();
for($i=2;$i<count($arrdata);$i++){
$rowx = explode(" ",$arrdata[$i]);
$arr1= ""; // and this is too
for($x=0;$x<count($rowx);$x++){
if($rowx[$x]!=""){
$arr1[] = $rowx[$x];
}
}
$arr2[] = $arr1;
}
for($i=0;$i<count($arr2);$i++){
$td .="<tr>";
for($j=0;$j<count($hcol)-1;$j++){
$td .= "<td style='border-right:0px solid #000'>".$arr2[$i][$j]."</td>"; //and it's($arr2[$i][$j]) give an error: Cannot use string offset as an array
}
$td .="</tr>";
}
benim kod sonra ve bunu çözdü:
$arr2= array(); //change this from $arr2="";
for($i=2;$i<count($arrdata);$i++){
$rowx = explode(" ",$arrdata[$i]);
$arr1=array(); //and this
for($x=0;$x<count($rowx);$x++){
if($rowx[$x]!=""){
$arr1[] = $rowx[$x];
}
}
$arr2[] = $arr1;
}
for($i=0;$i<count($arr2);$i++){
$td .="<tr>";
for($j=0;$j<count($hcol)-1;$j++){
$td .= "<td style='border-right:0px solid #000'>".$arr2[$i][$j]."</td>";
}
$td .="</tr>";
}
Thank's. Hope it's helped, and sorry if my english mess like boy's room :D