Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Fatal error: Call to undefined function FollowYou() in C:\wamp\www\oop-beg\ch4-6.php on line 23

Posted on 2013-12-09
5
Medium Priority
?
432 Views
Last Modified: 2013-12-10
<?php
class Animal{}
class Person{}
class GrizzlyBear extends Animal implements IThreat{
  function GrowlAtYou(){
    echo "Growwwwwwwwl!!";
  }
  function ChaseYou(){}
  function PounceOnYourCar(){}
  function EatYou(){}
  function BeThreatening(){
    GrowlAtYou();
    ChaseYou();
    PounceOnYourCar();
  }
}
class Cop extends Person implements IThreat{
  function FollowYou(){}
  function PullYouOver(){}
  function ArrestYou(){}
  function BeatYouSenseless(){}
function BeThreatening(){
  FollowYou();
  PullYouOver();
  ArrestYou();
}
}
interface IThreat{
  public function BeThreatening();
}
class ScaryRoad{
  public function __construct(){}
  public function DriveCar(array $threatening_object){
    //while driving down a scary road
    foreach ($threatening_object as $threat){
      $threat->BeThreatening();
    }
  }
}
//$cop1=new Cop();
$cop1=new Cop();
$grizzly1 = new GrizzlyBear();
$grizzly2 = new GrizzlyBear();

$road=new ScaryRoad();
$road->DriveCar($threats=array($cop1,$grizzly1,$grizzly2));

Open in new window


from an object oriented php tutorial

Fatal error: Call to undefined function FollowYou() in C:\wamp\www\oop-beg\ch4-6.php on line 23
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
5 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 1200 total points
ID: 39705811
Shouldn't it be this way?

class Cop extends Person implements IThreat{
  function FollowYou(){}
  function PullYouOver(){}
  function ArrestYou(){}
  function BeatYouSenseless(){}
function BeThreatening(){
  $this->FollowYou();
  $this->PullYouOver();
  $this->ArrestYou();
}
}

Open in new window

0
 
LVL 10

Expert Comment

by:ienaxxx
ID: 39706067
can you post a phpinfo(), please?
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 800 total points
ID: 39708312
Please review what you've been learning about scope and visibility and $this.  Forgetting $this-> is one of the most frequent coding errors for programmers who are moving from procedural to object oriented programming!  Expect this error in your own code; it's a mistake you will make and you'll be in good company because everyone makes this mistake!
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39708421
Oh, I see now you have the same error also in lines 12, 13 and 14, so in addition to the fix suggested in comment ID 39705811 you have to do the following:

function BeThreatening(){
  $this->FollowYou();
  $this->PullYouOver();
  $this->ArrestYou();
}

Open in new window

0
 

Author Closing Comment

by:rgb192
ID: 39709293
thanks for $this
and explanation about $this
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
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

609 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