Page 1 of 1

Class with PHP

Posted: Wed Aug 25, 2004 9:48 pm
by anhsoft
I am learning PHP, but i don't understand about CLASS in PHP, can you tell me about this, give: example...

thank you !

Posted: Wed Aug 25, 2004 9:55 pm
by John Cartwright
your best bet is to check out http://ca.php.net/language.oop over at php.net.

But basically in a nutshell classes are used to organise and allow you to pass variables from function to function inside the same class

for exmaple

Code: Select all

<?php

	class users
	{
		function loggedin()
 		{	
			return isset($_SESSION['loggedin']);
		}
		
		function displaywelcome()
		{		
			if 	($this->loggedin())
			{
				echo "hello";
			} 
		}
	}

?>
this isnt a very good example, but nonetheless an example. You can access variables from your functions withen the same class by using $this->

Posted: Wed Aug 25, 2004 10:07 pm
by Illusionist
also, using the above example, to make a new instance of that class you would do

Code: Select all

$user = new users();
but you may need a constructor(users) in the users class to make an instance that way... I'm not too familiar with using classes with php, as I haven't found a need for them yet

Posted: Wed Aug 25, 2004 10:15 pm
by John Cartwright
I truly hadn't really needed to use classes until I was developing a script which was pointed out to me that it would run out of memory.

Posted: Wed Aug 25, 2004 11:21 pm
by anhsoft
sorry, iam in Vietnam, i can't read english, i known a little english

have you some code better ...?

Posted: Wed Aug 25, 2004 11:56 pm
by feyd
the documentation is in several languages: http://www.php.net/docs.php if you can't speak any of those, we probably don't know where to look. try googling..