[ Prev ]
2020-10-21

-- Oct 21 In-Class Exercise Thread
<?php
trait myMethod{
  function foo(){
    echo "Mmmm foo!";
  }
}
class Goo{
  use myMethod;
  function what(){
    echo "What's foo?";
  }
}
$a = new Goo(); $a -> foo(); $a -> what();
?>
(Edited: 2020-10-21)
<?php trait myMethod{ function foo(){ echo "Mmmm foo!"; } } class Goo{ use myMethod; function what(){ echo "What's foo?"; } } $a = new Goo(); $a -> foo(); $a -> what(); ?>
2020-10-26

-- Oct 21 In-Class Exercise Thread
<?php
trait MyMethods{
    function foo(){
        echo "Mmmm foo!";
    }
} 
 
class Goo {
    use MyMethods;
    function what(){
        echo "What's foo?";
    }
} 
 
$x = new Goo();
$x->foo();
echo "<br />";
$x->what();
(Edited: 2020-10-26)
<pre><?php trait MyMethods{ function foo(){ echo "Mmmm foo!"; } } class Goo { use MyMethods; function what(){ echo "What's foo?"; } } $x = new Goo(); $x->foo(); echo "<br />"; $x->what();</pre>

-- Oct 21 In-Class Exercise Thread
<?php trait Methods {
    function Foo() { ]
      echo"Mmmm, foo!";
    }
} class Goo {
    use Methods;
    function what() {
      echo "What's foo?";
    }
} $a = new Goo(); $a->Foo(); $a->what();
<?php trait Methods { function Foo() { ] echo"Mmmm, foo!"; } } class Goo { use Methods; function what() { echo "What's foo?"; } } $a = new Goo(); $a->Foo(); $a->what();

-- Oct 21 In-Class Exercise Thread
<?php trait Traits{
    function foo(){
        echo "Mmmm foo!";
    }
}
class Goo{
    use Traits;
    def what():
        echo "What's foo?";
} $g = new Goo(); $g->foo(); $g->what();
<?php trait Traits{ function foo(){ echo "Mmmm foo!"; } } class Goo{ use Traits; def what(): echo "What's foo?"; } $g = new Goo(); $g->foo(); $g->what();
X