Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用来自其他类的PHP类变量_Php_Class_Variables - Fatal编程技术网

使用来自其他类的PHP类变量

使用来自其他类的PHP类变量,php,class,variables,Php,Class,Variables,我对一组代码有问题。我无法获取要显示的变量 下面是函数 public function __construct($id = self::DHMeetingCommentCardNew, DHMeetingGroup $meetingGroup = null) { global $DB; if ($id == self::DHMeetingCommentCardNew) { var_dump($meetingGrou

我对一组代码有问题。我无法获取要显示的变量

下面是函数

public function __construct($id = self::DHMeetingCommentCardNew, DHMeetingGroup $meetingGroup = null) { global $DB; if ($id == self::DHMeetingCommentCardNew) { var_dump($meetingGroup); $query = "INSERT INTO `" . self::DHMeetingCommentCardTable . "` (`UniqueID`, `MeetingGroup`) VALUES (UUID(), '{$meetingGroup['_id']}')"; $DB->query($query); $this->_id = $DB->lastID(); $this->_initializeNewCommentCard(); } else { $this->_id = intval($id); } } 公共函数构造($id=self::DHMeetingCommentCardNew,DHMeetingGroup$meetingGroup=null) { 全球$DB; 如果($id==self::DHMeetingCommentCardNew) { var_dump($meetingGroup); $query=“INSERT-INTO`.self::DHMeetingCommentCardTable.”(`UniqueID`,`MeetingGroup`)值(UUID(),'{$MeetingGroup[''u id']}'); $DB->query($query); $this->_id=$DB->lastID(); $this->_initializeNewCommentCard(); } 其他的 { $this->_id=intval($id); } } 我无法从$meetingGroup变量中获取ID

对于var_dump($meetingGroup),它会转储此文件

NULL object(DHMeetingGroup)#10745 (1) { ["_id":"DHMeetingGroup":private]=> int(11086) } 空对象(DHMeetingGroup)#10745(1){[“_id”:“DHMeetingGroup”:private]=>int(11086)}
只要属性定义为
property
,您就只能从同一实例(和同一类)而不是外部访问它


您唯一能做的就是将
\u id
属性在
DHMeetingGroup
中的声明方式从
private
更改为
public
尝试将此代码添加到类DHMeetingGroup中

public function get_id()
{
    return $this->_id;
}
然后改变这一行(我猜这门课叫DHMeetingCommentCard)


我将定义从private更改为public,现在var_dump正在将其输出。@user764429:我不明白你的意思
$query = "INSERT INTO `" . self::DHMeetingCommentCardTable . "` (`UniqueID`, `MeetingGroup`) VALUES (UUID(), '{$meetingGroup['_id']}')";
$query = "INSERT INTO `" . self::DHMeetingCommentCardTable . "` (`UniqueID`, `MeetingGroup`) VALUES (UUID(), '{$meetingGroup->get_id()}')";