Solved

instantiate the object to see all the echo statements

Posted on 2013-12-09
3
285 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
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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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 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 …

943 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

10 Experts available now in Live!

Get 1:1 Help Now