oop - how to echo function in php like this print(h(pow)? -


class fruits {  function g($str = 'fruits'){  $i=0; $new_str = ""; while ($i < strlen($str)-1){ $new_str = $new_str + $str[$i+1]; $i = $i + 1;  }  return $new_str; }  function f($str = 'fruits') {  if (strlen($str)== 0) { return ""; } else if  (strlen($str)== 1) { return $str; }  else { return $this->f($this->g($str)) + $str[0]; }  }  function h($n=1, $str = 'fruits'){  while ($n != 1){  if ($n % 2 == 0){ $n = $n/2; } else  { $n = 3*$n + 1; } $str = $this->f($str); } return $str; }  function pow($x, $y){ if (y==0) { return 1; }  else  { return $x * $this->pow($x, $y-1);  }  }   }      $obj = new fruits;   print(h(pow()); 

i want ask how echo function print(h(pow);?

first turn on error reporting with:

<?php     ini_set("display_errors", 1);     error_reporting(e_all); ?> 

and see (besides typos):

fatal error: call undefined function h() in ...

that because have class methods. have take instance of class call method it, e.g.

$obj = new fruits; echo $obj->h($obj->pow(4, 5)); 

this basic oop php. highly recommed use more meaningful function , variable names!


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -