Jump to content


Photo

OOP Problem


  • Please log in to reply
1 reply to this topic

#1 Demonic

Demonic
  • Members
  • PipPipPip
  • Advanced Member
  • 562 posts

Posted 03 September 2006 - 05:15 AM

<?php
class MyClass {
  var $statement;
  function PrintToScreen(){
  echo $statement;
  }
  }
  $class = new MyClass;
  $class->$statement = "hi";
  $class->PrintToScreen();
?>

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

#2 extrovertive

extrovertive
  • Members
  • PipPipPip
  • Advanced Member
  • 235 posts

Posted 03 September 2006 - 08:41 AM

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

class MyClass {
   var $statement;
  function PrintToScreen(){
  echo $this->statement;
  }
  }
  $class = new MyClass;
  $class->statement = "hi";
  $class->PrintToScreen();





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users