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 |
what is the importence of session.save_path in Php.ini file and wht changes u've to made before using sesssions in ur php program first time?
What is default session time and path in PHP. How to change it?
What is the best php version for wordpress?
Tell me which programming language does php resemble to?
how php works with oracle?
Hello I m 1.5 exp, i want code : ms word to Html in php,retrieve the words in ms word in to dispaly browser in (same format,alignment). pls help me everybody Regards selva
How to Calculate Internal links & External Link in Website.(For Example YAHOO WEBSITE)
Where do I run php code?
What are the features of php?
Do you know what does $globals means?
when you will get the message/error "headers already sent"?
How can I know that a variable is a number or not using a JavaScript?