Solved

instantiate the object to see all the echo statements

Posted on 2013-12-09
3
280 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 33

Accepted Solution

by:
Slick812 earned 500 total points
Comment Utility
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 108

Expert Comment

by:Ray Paseur
Comment Utility
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
Comment Utility
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 Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now