Jump to content

Calling functions from external class within functions


birdzhavefangs

Recommended Posts

So I'm having trouble getting a larger project to work- namely calling functions (from an outside class) within functions.  I'm sure this has been asked before, but I can't really think of a way to phrase it well enough for searching, so I apologize!

 

Here's my example:

First off is bob.php, the class file

<?php
class Bob {
   function loud( ) {
     echo "Bob\n";
   }
   function greet($name) {
     echo "Hello, ".$name."!\n";
   }
}
?>

 

And second is bobuser.php, that requires bob:

<?php
require_once("bob.php");
$B = new Bob;
$B->loud();
function bob2(){
 $B->loud();
}
bob2();
echo "oh noes";
?>

 

The output I want is:

Bob

Bob

oh noes!

 

Versus the output I'm getting is:

Bob

 

I'm working on large project right now, and I don't want to post it's code (due to mess, and laaarge size), hence the very simple example.  Thank you for your attention!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.