I have a class called : Auth
inside it i have 3 functions:
Make_Pass
Signup
Activate
Now a user enters all the information we require: Username, Email address
However, signup handles EVERYTHING, all the database work, but i need to generate a password inside that function, how do i call Make_Pass() inside Signup() ?
Thanks.
Class and Functions.
Moderator: General Moderators
Your are looking for $this
Read the PHP manual on OO basics for PHP..
BTW, using OO with PHP chewes quite a bit of resources, I don't really see any point in doing so unless you are building some dynamic object hierarchy system.. (It is very common to use for namespace-purposes, I believe it is much more efficient just prefixing functions/vars and using arrays for multiple instancing)..
?>
Code: Select all
<?php
class test {
function test () {
# Initialize
$this->setbeer(); # Set the default (by calling a function of its own instance)
}
function setbeer ($type='Sam Adams') {
$this->beer = $type;
}
function whatbeer (
return $this->beer;
}
}
$mybeer = new test();
echo $mybeer->whatbeer(); // Sam Adams
$mybeer->setbeer('Killians Red');
echo $mybeer->whatbeer(); // Killians red
?>BTW, using OO with PHP chewes quite a bit of resources, I don't really see any point in doing so unless you are building some dynamic object hierarchy system.. (It is very common to use for namespace-purposes, I believe it is much more efficient just prefixing functions/vars and using arrays for multiple instancing)..
?>
that is what it is for, within a class you can only have code in functions, doing something within your own instance require use of $this->functionname() or $this->variablename
You can also call the function statically in the class using :: , by doing so that function can not access anything else within the instance it was called from..
In your case you would save resources by keeping the make_pass function outside the class, unless it (that function) needs to access any other (self or inherited) functions, variables or child objects.
Basically, if you are used to VB-objects, self. is the same as $this->
Edit/Add: Oops, correction: VB users: Me. (not self.) is the same as $this-> , some other language(s) uses self but I don't recall which now (Delphi?), havent used those for quite some time
You can also call the function statically in the class using :: , by doing so that function can not access anything else within the instance it was called from..
In your case you would save resources by keeping the make_pass function outside the class, unless it (that function) needs to access any other (self or inherited) functions, variables or child objects.
Basically, if you are used to VB-objects, self. is the same as $this->
Edit/Add: Oops, correction: VB users: Me. (not self.) is the same as $this-> , some other language(s) uses self but I don't recall which now (Delphi?), havent used those for quite some time