Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

instantiate the object to see all the echo statements

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

886 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