Jump to content

Trying to understand functions & inheritance


WilliamNz

Recommended Posts

Hi there I am on a quest to understand to an intermediate level, using classes / functions & inheritance.

 

Heres what I have so far, this is echoing object#id1 instead of "TEVEEEZ!"

 

class soccer {

function roffle_lol($tevez) {
$this->$tevez;
return $tevez;
}

}
$lol = "TEVEZZZ!";
$result = new soccer($lol);
echo($result);

 

I orginally wanted to call the function roffle_lol from outside the class, rather than call the whole class which seems to be what I am doing in the line  " $result = new soccer($lol); "....

 

Any help appreciated :)

 

 

 

Not exactly sure what you want to achieve with your example....

 

<?php

  class soccer {

    private $tevez;

    function __construct($tevez) {
      $this->tevez = $tevez;
    }

    function roffle_lol() {
      return $this->tevez;
    }

  }

  $lol = "TEVEZZZ!";
  $soc = new soccer($lol);
  $result = $soc->roffle_lol();
  echo $result;

?>

 

there is no inheritance covered in this (or any of the above) example, and they are called methods not functions when they appear within a class.

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.