Jump to content

Class not working


SCook

Recommended Posts

I am having trouble with classes.  Here's a very simple class I made as a test, and the error message I get:
[code]
class dog {
  public function bark() {
      print("Whoof!");
  }
}
[/code]

And when I instantiate the class:

$dog = new dog;
$dog->bark;

and run it, I get this:


Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/ow1206/public_html/admin/class.class on line 4


Everything seems to be fine, but I just can't get it ro run, even with dot notation, and so on.  Any help would be great.
Link to comment
https://forums.phpfreaks.com/topic/34025-class-not-working/
Share on other sites

Don't let PHP4 discourage you from writing OO code.  I'd guess that > 90% of the code I've written professionally has been OO PHP4.  Your class example can be easily rewritten to work in PHP4:

[code]
<?php
class dog {
  function bark() {
      print("Whoof!");
  }
}

$dog = new dog();
$dog->bark();
?>
[/code]

Best,

Patrick
Link to comment
https://forums.phpfreaks.com/topic/34025-class-not-working/#findComment-159957
Share on other sites

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.