Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

instantiate the object to see all the echo statements

Posted on 2013-12-09
3
Medium Priority
?
304 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 2000 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 111

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

722 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