Jump to content

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.