php - PHP:在类中调用具有返回值的函数
问题描述
当我这样做时:
class MyClass
{
public function func1()
{
$temp = $this->func2();
return $temp;
}
function func2()
{
return "bla2";
}
}
该网站保持空白,似乎 PHP 因错误而崩溃(不过,error.log 中没有条目)
但是当我这样做时:
class MyClass
{
public function func1()
{
$temp = "bla1"; //$this->func2();
return $temp;
}
function func2()
{
return "bla2";
}
}
有用; “bla1”正在返回。显然我以错误的方式调用 func2 。它是如何正确的?
用我的 php-script 的这段摘录扩展我的原始帖子。我实际上已经将原始代码剥离并尝试了它 - >它仍然会导致错误。值得一提的是,它是 wordpress 的插件。如果没有函数调用,它确实可以工作并返回由 wordpress 显示的文本。
<?php
add_shortcode("pd",array("pdCategories","ShortcodeParse_c"));
$pd = new pdCategories();
class pdCategories
{
public function ShortcodeParse_c($atts)
{
$temp = "";
$temp.= "test<br>"; //this works
$temp.= $atts["category"]; //this also works
$temp.= $this->ShowCategories_c($atts["category"]); //this causes an error
return $temp;
}
private function ShowCategories_c($kats)
{
$temp = "starting...<br>"; //init
return $temp;
}
}
?>
解决方案
推荐阅读
- swift - 上传个人资料图片时 Firebase 应用程序崩溃
- atmel - sim800和sim900的区别
- android - React Native TextInput 多行底部
- reactjs - 尝试发布请求时反应原生发出警告
- sql - 根据 Oracle 版本执行查询
- c# - 如何修复在 LevelValue 更改时生成对象的减少时间
- php - 如何从 HTML 表中获取数据
- memory - 为什么 Racket 在这里以不同的值 (current-memory-use) 开始?
- algorithm - 无法为 while & if 语句找到正确的 Big O
- javascript - 如何避免登录用户通过控制台使用 ajax?