大家好,祝贺您的出色工作, 我的问题是:我想在不实例化“所有”类的情况下将一个对象从一个类的构造函数(课程)推到另一个类(全部)的数组属性(课程)。
我试图做这样的事情All :: array_push($ Courses,$ this)
课程课程
<?php
class Course
{
public $Title;
public $Stream;
public $Type;
public $StartDate;
public $EndDate;
function __construct($title,$stream,$type,$startDate,$endDate)
{
$this->Title = $title;
$this->Stream = $stream;
$this->Type = $type;
$this->StartDate = $startDate;
$this->EndDate = $endDate;
//This is C# way
All.Courses.Add(this);
//I tried to do something like this
//All::array_push($Courses,$this) but not worked
}
}
?>
所有班级
<?php
class All
{
public static $Students = array();
public static $Assignments = array();
public static $Trainers = array();
public static $Courses = array();
public static $AllCoursesWithTheirStudents = array();
public static $AllCoursesWithTheirTrainers = array();
public static $AllCoursesWithTheirAssignments = array();
public static $AllStudentsWithTheirAssignments = array();
?>