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

&lt;pre&gt; &lt;?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();

&lt;pre&gt;

<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

&lt;?php

trait MyMethods { function foo() { echo &quot;Mmmm foo!&quot;; } }

class Goo { use MyMethods;

function what() {
    echo "What's foo?";
}

}

a = new Goo(); a -&gt; foo(); $a -&gt; 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

&lt;?php

trait FooTrait { function foo() { echo &quot;Mmmm, foo!&quot;; } }

class Goo { use FooTrait;

function what() { echo &quot;What&#039;s foo?&quot;; } }

x = new Goo(); x-&gt;foo(); $x-&gt;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

&lt;?php

trait myMethod {

function foo() {
echo "Mmmm foo!";
}

}

class Goo {

function what() {
	echo "What's foo?";
}

use myMethod; 

}

a = new Goo(); a-&gt;foo(); $a-&gt;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

&lt;?php trait MyMethods { function getFoo() { echo &quot;Mmmm foo!&quot;; }

} class Goo { function what() { echo &quot;What&#039;s foo?&quot;; } use MyMethods; }

g = new Goo; g-&gt;getFoo(); $g-&gt;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

&lt;?php trait test { function foo() {echo &quot;Mmmm foo!&quot;;} } class Goo { use test; function what() {echo &quot;What&#039;s foo?&quot;;} }

a = new Goo(); a-&gt;foo(); $a-&gt;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

&lt;?php

trait TraitMethods { function foo() { echo&quot;Mmmm, foo!&quot;; } }

class Goo { use TraitMethods; function what() { echo &quot;What&#039;s foo?&quot;; } }

f = new Goo(); f-&gt;foo(); $f-&gt;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