PHP code example of oihana / php-traits

1. Go to this page and download the library: Download oihana/php-traits library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

oihana / php-traits example snippets


trait GreetTrait
{
    public function hello(): string
    {
        return "Hi, I'm {$this->name}";
    }
}

class User
{
    use GreetTrait; // ← the class instantly gains the hello() method

    public function __construct( public string $name ) {}
}

echo ( new User('Ada') )->hello(); // Hi, I'm Ada
bash
composer