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
420 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 108

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

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

896 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

19 Experts available now in Live!

Get 1:1 Help Now