PHP property_exists() 出现问题
大家好...当我运行下面的代码时, if(property_exists(get_class($puzzleCharacters_encrypted), $solutionCharacter) 不断评估为 false,但前面的 echo 语句显示了正确的信息,所以我可能缺少任何属性吗?(PHP 版本 5.2.11)
$puzzle_solution = $currentPuzzleData->getVal("text");
$puzzle_encryption = "";
for ($i = 0; $i < strlen($puzzle_solution); $i++)
{
$solutionCharacter = substr($puzzle_solution, $i, 1);
echo ("\$solutionCharacter = " . $solutionCharacter . "<br />\n");
echo ("\$puzzleCharacters_encrypted->getVal(" . $solutionCharacter . ") = " . $puzzleCharacters_encrypted->getVal($solutionCharacter) . "<br />\n");
if (property_exists(get_class($puzzleCharacters_encrypted), $solutionCharacter))
{
$encryptionCharacter = $puzzleCharacters_encrypted->getVal($solutionCharacter);
$puzzle_encryption .= $encryptionCharacter;
}
else
{
$puzzle_encryption .= $solutionCharacter;
}
}
echo ("<br />\n" . $puzzle_solution);
echo ("<br />\n" . $puzzle_encryption);
谢谢!
Hey all... When I run the code below, the if(property_exists(get_class($puzzleCharacters_encrypted), $solutionCharacter) keeps evaluating to false, but the echo statements preceding that are showing the correct information, so the properties are definitely there. Anything I might be missing? (PHP Version 5.2.11)
$puzzle_solution = $currentPuzzleData->getVal("text");
$puzzle_encryption = "";
for ($i = 0; $i < strlen($puzzle_solution); $i++)
{
$solutionCharacter = substr($puzzle_solution, $i, 1);
echo ("\$solutionCharacter = " . $solutionCharacter . "<br />\n");
echo ("\$puzzleCharacters_encrypted->getVal(" . $solutionCharacter . ") = " . $puzzleCharacters_encrypted->getVal($solutionCharacter) . "<br />\n");
if (property_exists(get_class($puzzleCharacters_encrypted), $solutionCharacter))
{
$encryptionCharacter = $puzzleCharacters_encrypted->getVal($solutionCharacter);
$puzzle_encryption .= $encryptionCharacter;
}
else
{
$puzzle_encryption .= $solutionCharacter;
}
}
echo ("<br />\n" . $puzzle_solution);
echo ("<br />\n" . $puzzle_encryption);
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第二个
echo
语句实际上并不是查询对象,而是输出一个字符串,其中放置了$solutionCharacter
。这并不能证明该财产确实存在。然后,您将查询
$puzzleCharacters_encrypted
的class
中的属性。该属性很可能不是在类中定义的,而是在对象中定义的。如果你尝试会发生什么
?
The second
echo
statement is not actually querying the object, it is outputting a string in which$solutionCharacter
is put. That is no evidence that the property actually exists.Then, you are querying for the property in the
class
of$puzzleCharacters_encrypted
. It may well be that the property is not defined in the class, but in the object.What happens if you try
?
由于代码的原因,将此作为答案发布...
printr ($puzzleCharacters_encrypted) 的输出:
Posting this as an answer because of the code...
The output of printr ($puzzleCharacters_encrypted):