FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Calling Functions





coreymanshack
I want to call a function from within a function from within a class..

Code:
<?
class Template {
   public $template;
     function load($filepath) {
      $this->template = file_get_contents($filepath);
     }
     function replace($var, $content) {
      $this->template = str_replace("#$var#", $content, $this->template);
     }
     function loopit($var, $content, $counter, $num) {
            $all .= "$data";
            global $all;
            global $var;
            if($counter==$num){
            replace($var, $all);
            }
    }
    function publish() {
      eval("?>".$this->template."<?");
     }
}
?>



function loopit($var, $content, $counter, $num) {
$all .= "$data";
global $all;
global $var;
if($counter==$num){
//HERE I WANT TO CALL the replace function as defined in this file, and //send it "all "and "var", how do i do that? replace($var, $all);
}
kv
Code:


$this->replace($var, $all);

coreymanshack
kv wrote:
Code:


$this->replace($var, $all);




Ok I tried that, and now the function isn't passing the variables i don't guess.

Code:
<?
class Template {
   public $template;
    function load($filepath) {
      $this->template = file_get_contents($filepath);
    }
    function replace($var, $content) {
      $this->template = str_replace("#$var#", $content, $this->template);
    }
    function loopit($var, $content, $counter, $num) {
      $all .= "$data";
      global $all;
      global $var;
         if($counter==$num){
            $this->replace($var, $all);
         }
   }
   function publish() {
      eval("?>".$this->template."<?");
    }
}
?>


Is there something I need to do to the variables for them to be passed onto the replace() function?

EDIT: I finished the code, it doesn't work how I wanted it to, BUT the question I asked here has been answered.
kv
Check the $var variable in the below code.
Code:


    function loopit($var, $content, $counter, $num) {
      $all .= "$data";
      global $all;
      global $var;
         if($counter==$num){
            $this->replace($var, $all);
         }
   }



It is being passed as a variable to function loopit as well as declared global. You should do one of them, not both. Rectify this and your code should work.
Related topics
Windows Vista Virus!!
Executing a .sql file through PHP
PHP Tutorials
Frankfurt Motor Show, 2005
Programming links, info, and tutorials
php image exif functions
Fashionable Nonsense by Alan Sokal and Jean Bricmont
DOM XML Functions
writing COM components in Perl
The .tpl mess
Multidimensional Arrays & passing info between windows
Cellphone Functions
PHP VS ASP
Javascript, how to calling a function with in a body ?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.