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
415 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 30

Accepted Solution

by:
Marco Gasi earned 300 total points
Comment Utility
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
Comment Utility
can you post a phpinfo(), please?
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 200 total points
Comment Utility
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 30

Expert Comment

by:Marco Gasi
Comment Utility
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
Comment Utility
thanks for $this
and explanation about $this
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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 look for a specific file type in a local or remote server directory using PHP.

744 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

14 Experts available now in Live!

Get 1:1 Help Now