This is with your php version, It must have been changed, please check the version of php and try to update that.
Parent的类构造函数调用错误?
I'm trying to call parent class constructor but it throws an error
Fatal error: Cannot call constructor
and the same code was working well before, I didn't change anything and but suddenly don't know what could have happened, It is throwing this error.
I've read some answers on stackoverflow, but they say that your parent class doesn't contain a constructor, well, this is not my case I have constructor in my parent class. Here's my code:
class DB
{
var $con;
public function __construct()
{
require_once 'configs/dbconfig.php';
$this->connect();
}
function connect()
{
try{
$this->con = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME,DB_USER,DB_PASS);
$this->con->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
}catch(PDOException $ex) {
echo $ex->getMessage();
}
}
}
and then I have a class Posts which is extending DB and calling DB's constructor.
class Posts extends DB
{
var $user_id;
public function __construct($user_id)
{
parent::__construct();
$this->user_id = $user_id;
}
function get_posts($search,$pages,$since_id=0,$max_id=false,$count=20,$status='active')
{
$extra = '';
if($search) $extra .= " AND text LIKE CONCAT('%',:search,'%')";
if(!empty($pages)) $extra .= " AND page IN('".implode("','", $pages)."')";
if(!empty($status) && $status != 'all') $extra .= " AND status=:status";
$max_id = ($max_id) ? $max_id : time();
$sqlCommand = "SELECT id,pid,text,media,media_url,type,name,u_id,username,user_profile_url,user_photo_url,post_url,date,status,source,page_id FROM ".POSTS." WHERE date>=:since_id AND date<=:max_id".$extra." AND user_id=:user_id ORDER BY date DESC LIMIT $count";
$params = array(':since_id'=>$since_id,':max_id'=>$max_id,':user_id'=>$this->user_id);
if($search) $params[':search'] = $search;
if($status && $status != 'all') $params[':status'] = $status;
$posts = $this->fetch($sqlCommand,$params);
return $posts;
}
}
- 点赞
- 写回答
- 关注问题
- 收藏
- 复制链接分享
- 邀请回答
3条回答
为你推荐
- Qt怎么控制提升的widget内的控件?
- 子类构造方法的参数名要和其父类构造方法的参数名相同吗?我怎么没有查到相关信息,这题答案说是AC,我把super方法放第一行后编译没报错呀
- vs2013+Qt5.5.0 主项目调用Qt Libary中新建的Widget链接报错
- c++
- 1个回答
- Qt 如何show()类不产生界面,只调用其中的构造函数?
- c++
- 1个回答
- Parent的类构造函数调用错误?
- constructor
- php
- 3个回答
- qt 自定义类的私有属性在别的函数里不能用,只能在构造函数里使用
- c++
- 3个回答
- QT调试时遇到 Signal name : SIGSEGV Signal meaning : Segmentation fault,但是我已经初始化了变量。
- c++
- 1个回答
- RecycleView代码不更新!
- recycview中添加底部按钮问题。
- 关于Thread类中的start()方法和run()方法
- IT行业问题
- 计算机技术
- it技术
- 编程语言问答
- 互联网问答
- 0个回答
- qt中自定义槽函数怎么调用该类中的控件指针
- 控件
- 指针
- qt
- 2个回答
- 用QT写了一个0槽和信号相关的代码,代码编译成功,但是槽函数始终接收不到信号,
- 信号
- 槽函数
- qt
- 1个回答