I am learning PHP, but i don't understand about CLASS in PHP, can you tell me about this, give: example...
thank you !
Class with PHP
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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
this isnt a very good example, but nonetheless an example. You can access variables from your functions withen the same class by using $this->
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";
}
}
}
?>-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
also, using the above example, to make a new instance of that class you would do
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
Code: Select all
$user = new users();- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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..