![]() |
PHP class
I made a php class, but how do I use it?
I know that you make an object using the constructor: :
$obj = new ClassName();:
$obj->myMethod();Any help would be great, as well as a good tutorial on classes in PHP. Thanks |
1. We need to see your source to pin point your problem, that pseudo code doesn't tell us much.
2. What version of PHP? |
Well here it is, but it's not much different from what I posted before.
[php] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Test</title> </head> <?php $obj = new myClass(); echo $obj->write(); ?> <body> </body> </html> [/php] And this is the class: [php] <?php class myClass{ var $h; //constructor function myClass(){ $h = "Hello"; } function write(){ return $h; } } ?> [/php] And I am writing it in php 5.1.4 |
Try using include_once() or require_once() to put your class definition in the file where it's being used.
:
<?php |
Your class should be as follows dark_omen:
:
<?php |
Quote:
|
$this->$h should be $this->h. I believe his biggest problem was not having the class definition available in the file where he used it.
|
Good looking out DaWei, I accidentally left that dollar sign in there. Here is the properly revised code.
:
<?php |
thanks for the info
|
| All times are GMT -5. The time now is 12:48 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC