Jump to content

Archived

This topic is now archived and is closed to further replies.

Demonic

OOP Problem

Recommended Posts

[code=php:0]
<?php
class MyClass {
  var $statement;
  function PrintToScreen(){
  echo $statement;
  }
  }
  $class = new MyClass;
  $class->$statement = "hi";
  $class->PrintToScreen();
?>
[/code]

I tried doing this but it wont print hi any suggestions?

Share this post


Link to post
Share on other sites
If you want to do something with variables defined in your class, you must use a $this pointer to access it within the class.

[code=php:0]
class MyClass {
  var $statement;
  function PrintToScreen(){
  echo $this->statement;
  }
  }
  $class = new MyClass;
  $class->statement = "hi";
  $class->PrintToScreen();
[/code]

Share this post


Link to post
Share on other sites

×

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.