This post was last edited by jerryleeee on 2013-10-25 03:26:59
Class Editor{var $Error = '; var $Pages; function Vol () {$Pages = array (); $this->pages[] = new Page;}} Class Page{var $Id = "; var $BackImage; function Vol () {$BackImage = array (); $this $BackImage [] = new Decorator;}} Class Decorator{var $Ext = ';} _________________________________________________________//When I use this class $editor = new Editor; $Editor->vol (); $ Editor->pages[0]->vol (); Object definition complete? I only initialized the class Decorator object under Pages[0], why I can directly use page[2] and the class Decorator in all the other elements of the page array, without needing me $editor->pages[2]- >vol ()? $Editor->pages[0]->backimage[0]->ext = ' str '; $Editor->pages[2]->backimage[2]->ext = ' str2 '; $ Editor->pages[5]->backimage[4]->ext = ' STR6 '; This uses no error
Reply to discussion (solution)
This is supposed to be a warning.
Class editor{ var $Error = '; var $Pages; Function Vol () { $Pages = array (); $this->pages[] = new page; }} Class page{ var $Id = '; var $BackImage; Function Vol () { $BackImage = array ();// $this $BackImage [] = new Decorator;//fatal Error:cannot Use [] for reading $this->backimage[] = new Decorator;//can only be written because $BackImage is an array }} class decorator{ VA R $Ext = ";} $Editor = new Editor; $Editor->vol (); $Editor->pages[0]->vol ();
Not even a grammar check!
I'll give it a try.
[Color= #993300] feeling to find out why: [/color]
When I was using this class,
$Editor = new Editor;
$Editor->vol ();
$Editor->pages[0]->vol (); Object definition complete? I only initialized the class decorator object under Pages[0],
Why can I use the class Decorator in the other elements of page[2] and all the page arrays directly below?
Without needing my $editor->pages[2]->vol ()?
$Editor->name = "XLC";
echo "
";
$Editor->pages[10]->backimage[10]->name = ' str ';
Echo $Editor->pages[10]->backimage[10]->name;
Var_dump ($Editor);
The output is:
Strobject (Editor) #1 (2) {["Error"]=> string (0) "" ["Pages"]=> Array (2) {[0]=> Object (page) #2 (2) {["Id"]=> String (0) "" ["Backimage"]=> Array (1) {[0]=> object (Decorator) #3 (1) {["Ext"]=> string (0) ""}}} [10]=> ob Ject (StdClass) #4 (1) {["Backimage"]=> Array (1) {[10]=> object (StdClass) #5 (1) {["Name"]=> string (3) "Str"}} } } }
Please check the data pages[10] The key value, in fact, he created a person Stdclass class page is not an instance of the page class, this should be the PHP5 feature bar.
At first I thought it was the magic method inside the problem, but later decided a bit, not.
No error should be your PHP set the reporting level
{
$BackImage = Array (1,2,3,4);
$this->backimage[] = new Decorator;
There are two more sentences to help you understand
Print_r ($BackImage);
Print_r ($this->backimage);
}
You need to understand the similarities and differences between the properties of a class and the general variables that occur within a class
Suggest you should learn the inheritance of class, can clarify and simplify your ideas above, reduce the use of object chain, method chain
Thank you, everyone upstairs, it's good to have you! Thanks again!!