Solved

instantiate the object to see all the echo statements

Posted on 2013-12-09
3
303 Views
Last Modified: 2013-12-10
<?php
class Person{}
class Vegetable{}

interface ISweat{
  function MakeYouSweat();
}

class AttractiveStranger extends Person implements ISweat{
  public function LookAtYou(){}
  public function SmileAtYou(){}
  public function TalkToYou(){}
  
  public function MakeYouSweat(){
    $this->LookAtYou();
    $this->SmileAtYou();
    $this->TalkToYou();
  }
}
class Pepper extends Vegetable{
  public function BurnYourTongue(){}
  public function CauseBathroomEmergency(){}
  public function MakeYouSweat(){
    $this->BurnYourTongue();
    $this->CauseBathroomEmergency();
  }
}

class CollegeBar implements ISweat{
  public function __construct(){
    $attractivestranger=new AttractiveStranger();
    $hotpepper=new Pepper();
    $thing1=$attractivestranger->MakeYouSweat();
    $thing2=$hotpepper->MakeYouSweat();
    $thingsThatMakeYouSweat=array($thing1,$thing2);
    SitAtBar($thingsThatMakeYouSweat);
  }
  void SitAtBar(){
    //when you are sitting at the Bar
    foreach($thingsThatMakeYouSweat as $value){
      
    }
  }
}

Open in new window


This is the answer from
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28313720.html

but what are examples of ways I could instantiate the object to see all the echo statements
0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 34

Accepted Solution

by:
Slick812 earned 500 total points
ID: 39707779
You examples you first gave are POOR for learning the way you build the definition of a CLASS, since they only show how to correctly place the PHP syntax for the extended CLASS as -
class AttractiveStranger extends Person implements ISweat{
    that is a class extension AND implements an interface, but it shows almost nothing about USING a CLASS to do programming work, as all of the methods are mostly EMPTY,  and can not do ANYTHING, I only placed the "echo" in methods so there would be something there, but the echos are all useless and do no actual useful work, just for a learning exersize I guess? ? ?


Here is some code to show how to call the methods
<html><head><title>EE Fromula</title></head><body bgcolor="#e3f7ff"><h2>Test for EE Fromula</h2>
<p>
<?php

class Person{public $name='name';
public function echoName(){echo $this->name;}
}
class Vegetable{public $type='type';
public function echoType(){echo $this->type;}
}

interface ISweat{
  function MakeYouSweat();
}

class AttractiveStranger extends Person implements ISweat{
  public function LookAtYou(){echo $this->name.'=LookAtYou-';}
  public function SmileAtYou(){$this->echoName(); echo '=SmileAtYou-';}
  public function TalkToYou(){echo 'SmileAtYou-';}
  
  public function MakeYouSweat(){
    $this->LookAtYou();
    $this->SmileAtYou();
    $this->TalkToYou();
    return 'AttractiveStranger-MakeYouSweat';
  }
}
class Pepper extends Vegetable{
  public function BurnYourTongue(){echo $this->type.'=BurnYourTongue-';}
  public function CauseBathroomEmergency(){$this->echoType();  echo 'CauseBathroomEmergency-';}
  public function MakeYouSweat(){
    $this->BurnYourTongue();
    $this->CauseBathroomEmergency();
    return 'Pepper-MakeYouSweat';
  }
}

class CollegeBar implements ISweat{
  public function __construct(){
    $attractivestranger=new AttractiveStranger();
    $hotpepper=new Pepper();
    $thing1=$attractivestranger->MakeYouSweat();
    $thing2=$hotpepper->MakeYouSweat();
    $arrayValues=array($thing1,$thing2);
    $this->SitAtBar($arrayValues);
  }
  public function SitAtBar($things){
    //when you are sitting at the Bar
    foreach($things as $value){
      echo $value.'-';
    }
  }

  public function MakeYouSweat(){
  echo 'Perspiration';
  }
}

echo '<hr>CollegeBar Init = ';
$cb = new CollegeBar; // when you create this it echos out it's SitAtBar method
echo ' | | '.$cb->MakeYouSweat();
	
echo '<hr>AttractiveStranger stuff =<br />';
$at = new AttractiveStranger;
// $at->name the name is from the PARENT CLASS
echo $at->name.' | '.$at->MakeYouSweat().'<hr>Pepper stuff =<br />';
$pep = new Pepper;
$pep->echoType();// echoType() from the PARENT CLASS
echo ' || '.$pep->MakeYouSweat();

?>
</P>
<br />The End
</body></html>

Open in new window

I really have no Idea what you are suppose to be learning from this tutorial example? ?
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39708244
Instead of using echo (which will call the __toString() method and will deliberately remove most of the character of the object), use var_dump() to print out the objects before and after you call the methods.  By comparing the objects you will be able to see the effect of the programming.
0
 

Author Closing Comment

by:rgb192
ID: 39709229
Thanks
code moved in my debugger which taught me.
And there was nice easy to read output.

var_dump  I opened another question about what Ray wrote.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28314960.html
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question