PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Oh... well I gotta tell you.. I was having a hard time grasping the concept of classes and really understanding exactly what their purpose is until I started using PHP5's public and private keywords and researching php design patterns... once you get the basics down, research that stuff.
<?php
class Main
{
var $nick;
function Main($name)
{
$this->nick = $name;
}
function hello()
{
echo 'Hello ' . $this->nick;
}
}
$main = new Main('ambrose');
$main->hello();
?>
In PHP4 the name of the function called when an object is created (called the Constructor) is the same name as the class. In PHP5 it is called __construct() (but the PHP4 name also works).