Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


What are traits? How is it used in php?



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

Post New Answer

More PHP Interview Questions

What is phpsessid?

0 Answers  


A process can run only in the background. State Whether True or False?

0 Answers  


What version of php do I have windows?

0 Answers  


What is fetch array in php?

0 Answers  


What does == mean in php?

0 Answers  


how many type of url?

1 Answers  


Are php session secure?

0 Answers  


What is the purpose of the following files having extensions: frm, myd, and myi? What these files contain?

0 Answers  


Which is incorrect with respect to separating php code and html?

0 Answers  


Is php front end or back end?

0 Answers  


What is php session and how it works?

0 Answers  


How do I find out the number of parameters passed into function9?

0 Answers  


Categories