Created
May 15, 2012 14:36
-
-
Save tentacode/2702262 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SomeObject | |
{ | |
use \FooTraits\SomeTrait; | |
public function getSomeRequiredParameter() | |
{ | |
return 'foo'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace FooTraits; | |
trait SomeTrait | |
{ | |
abstract function getSomeRequiredParameter(); | |
public function doSomething() | |
{ | |
$parameter = $this->getSomeRequiredParameter(); | |
} | |
} |
L'exemple est générique au possible :) mais l'utilisation finale est bien un Trait, je voulais rester générique au possible pour pas trop complexifier la discussion.
Et oui, cet exemple marche, je voulais juste savoir si il pouvait y avoir une façon un peu plus proprette de faire tourner le problème.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Je trouve que c'est compliqué de voir le bon et le mauvais à travers cet exemple. La seule remarque que je peux faire ici, c'est de remplacer le Trait par une abstract et un héritage.
D'après la doc (http://fr.php.net/trait#language.oop5.traits.abstract) ce que tu fais à l'air bon mais je ne vois pas trop l'intérêt dans cet exemple.