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
424 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
5 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 300 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 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 200 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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…
The viewer will learn how to count occurrences of each item in an array.

829 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