I want to learn php5 !!

Source: Internet
Author: User
Tags php code throw exception
PHP code :--------------------------------------------------------------------------------
Function FactoryMethod ($ class_type)
{
Switch ($ class_type)
{
Case "foo ":
$ Obj = new MyFoo ();
Break;
Case "bar ":
$ Obj = new MyBar ();
Break;
}
Return $ obj;
}
$ Object = FactoryMethod ("foo ");
$ Object-> method ()
$ Copy_of_object = $ object->__ clone ();
Class MyClass
{
Function _ destruct ()
{
... // Run destructor code
}
}
Delete $ object;
Class Shape {
Function _ construct ()
{
// Shape initialization code
...
}
...
};
Class Square extends Shape
{
Function _ construct ()
{
Parent: :__ construct ();
// Square-specific initialization code
...
}
...
};
Class foo
{
Private $ priv_var;
Function some_method (...)
{
$ This-> priv_var = ...; // Written on zend: $ priv_var = ...; I have never tried.
}
};
Class Logger
{
Static $ m_Instance = NULL;
Function Instance ()
{
If (Logger ::$ m_Instance = NULL)
{
Logger: $ m_Instance = new Logger ();
}
Return Logger: $ m_Instance;
}
Function Log ()
{
...
}
};
$ Logger = Logger: Instance ();
$ Logger-> Log (...);
Try
{
... Code
If (failure)
{
Throw new MyException ("Failure ");
}
... Code
}
Catch ($ exception)
{
... Handle exception
Throw $ exception; // Re-throw exception.
}

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.