Jump to content

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.

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.