Understanding for new students

Source: Internet
Author: User
In beginner's learning, I want to understand this post. at last, the post was edited by xuzuning from 2012-11-1922: 06: 50 & lt ;? Phpinterface & nbsp; PCI {function & nbsp; start (); function & nbsp; stop () ;}class & nbsp; N beginner class learning, understanding
This post was last edited by xuzuning at 22:06:50, January 19 ,.
 Interface PCI
{
Function start ();
Function stop ();
}
Class NetCard implements PCI
{
Function start ()
{
Echo "network connection successful
";
}
Function stop ()
{
Echo "network disconnected
";
}
}
Class SoundCard implements PCI
{
Function start ()
{
Echo "sound available
";
}
Function stop ()
{
Echo "no sound card device is available
";
}
}
Class ViewCard implements PCI
{
Function start ()
{
Echo "show image
";
}
Function stop ()
{
Echo "no available video card device
";
}
}
Class MainBoard
{
Function usePCI ($ pci)
{
$ Pci-> start ();
$ Pci-> stop ();
}
}
Class Person
{
Function install ()
{
$ Mb = new MainBoard ();

}
}
$ P = new Person ();
$ P-> install ();
$ Nc = new NetCard;
$ Mb-> usePCI ($ nc );
// The Program reports such an error and does not understand it,
Fatal error: Call to a member function start () on a non-object in C: \ wamp \ www \ PCI. php on line 63

------ Solution --------------------
Class Person
{
Function install ()
{
$ Mb = new MainBoard ();

}
}
Do you mean this?
$ Mb is created in the install method. if the method is complete, no more
It does not change the scope of a variable because it is a class.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.