What are traits? How is it used in php?
Answer / zahid
In PHP, a trait is a way to enable developers to reuse methods of independent classes that exist in different inheritance hierarchies.
Simply put, traits allow you to create desirable methods in a class setting, using the trait keyword. You can then inherit this class through the use keyword
Example:
trait hello {
public function message1() {
echo "Nature is precious,
";
}
}
trait world{
public function message2() {
echo "So Let us unite to preserve it";
}
}
class InUnity {
use hello;
}
class WeCan {
use hello, world;
}
$obj = new InUnity();
$obj->message1();
echo "****************
";
$obj2 = new WeCan();
$obj2->message1();
$obj2->message2();
| Is This Answer Correct ? | 0 Yes | 0 No |
A process is identified by a unique___
What is the difference between array_map () and array_shift ()?
How to select a database in php?
Why php is widely used?
Write a statement to show the joining of multiple comparisons in php?
how will i set pagination ?
What happens if an expected input field was not submitted?
How can we submit a form without a submit buttom?
12 Answers A1 Technology, IBM,
Explain the difference between isset() and empty()?
What does the arrow mean in php?
How about integrating an iKode Newsletter Server at my independent Wordpress blog site? I just wanna visitort can subscribe my blog when they like it and I can send some interested articles or events to them regularly to establish good relationship.
i have designed a registration form in html (registration.html) and to insert user details in database i have designed a submit form in php (submit_registration.php) but when i click on submit button in registration.html it opens a dialogue box which asks for open or save php(submit_registration.php) even though i have already installed apache HTTP server and php version 5 on my computer and i am using mysql as backend. plz suggest me what should i do????