2020-10-20

Oct 21 In-Class Exercise Thread.

Please post your solutions to the Oct 21 In-Class Exercise to this thread.
Best,
Chris
Please post your solutions to the Oct 21 In-Class Exercise to this thread. Best, Chris
2020-10-21

-- Oct 21 In-Class Exercise Thread
 <?php
 trait MyMethods
 {
     function Foo() { echo"Mmmm, foo!"; }
 }
 class Goo
 {
     use MyMethods; //as if I had written the code in MyMethods here
     function what() { echo "What's foo?";}
 }
 $a = new Goo();
 $a->Foo();
 $a->what();
<?php trait MyMethods { function Foo() { echo"Mmmm, foo!"; } } class Goo { use MyMethods; //as if I had written the code in MyMethods here function what() { echo "What's foo?";} } $a = new Goo(); $a->Foo(); $a->what();

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

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

-- Oct 21 In-Class Exercise Thread
Resource Description for InClass.png
((resource:InClass.png|Resource Description for InClass.png))

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

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

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

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

-- Oct 21 In-Class Exercise Thread
<?php
trait TraitMethods
 {
       function foo() 
       { 
	  echo"Mmmm, foo!"; 
       }
 }
 
class Goo
 {
     use TraitMethods; 
     function what()
	{ 
	   echo "What's foo?";
	}
 }
 
$f = new Goo(); $f->foo(); $f->what();
(Edited: 2020-10-21)
<?php trait TraitMethods { function foo() { echo"Mmmm, foo!"; } } class Goo { use TraitMethods; function what() { echo "What's foo?"; } } $f = new Goo(); $f->foo(); $f->what();
[ Next ]
X