city coder, I don't think you have a clear understanding of what "static" means in our conversation above.
Your function readCustomer() is not a static function. You will never be able to access it with the syntax Customer::readCustomer().
In php5, there are four types of methods (functions within a class)(these actually apply to class variables (properties) as well):
1. public. A "public" function can be accessed by code from outside the class (e.g., from you regular php scripts) after you have created an object from the class. The syntax is like this: $object = new class();, then $object->public_method();. "Public" is the default method type. If you don't declare otherwise (as you are not), then your method will be "public."
2. protected. Protected methods can be used only by the class itself, and by any class that extend it. This means that the method can be used by your classes, but can't be accessed or triggered directly by any outside code. So, $class->protected_method(); will work if it is a line of code inside the class (or in a class that extends the class), but if you write it in your regular script, it won't.
3. private. Private methods are like protected methods, except they can only be accessed by their own class (classes that extend the method's class have no access, nor does any outside code).
4. static. A static method can be accessed from anywhere, even if there is no related object. This is the type that uses the syntax class::static_method();. Static methods are usually utility functions, or other things that you might do frequently but don't need the support of the entire class.
Edit: They also have no access to the rest of the class (except other static methods, of course) because they aren't working from "inside" the object, even if the object exists. So a static method could not be accessed like this: $object = new class(); $object->static_method();, nor can they access other class functions by using $this->some_non-static_method();. Really, it might as well be a single function written outside the class, but it is a good way to keep related functions organized.
The rest of it looks functional enough (conceptually; once you finish writing it, of course), but I do have a suggestion.
It seems that (in this example) you want to use the readCustomer method to "start up" your class. If so, there is a method you could be using called __construct() (two underscores). The __construct method, if present, is run automatically (or, as php.net says, "automagically") when an object is created. So, if you write it like this:
PHP Code:
<?php
class Customer {
private $fName;
private $lName;
private $errorOccurred;
private $errorText;
function __construct($email = '') {
// set your SQL statement
// if there are results
// use class methods to assign the values to the class variables
// otherwise, return error message
}
}
?>
then simply calling $customer = new Customer('test@test.com'); will return an object with all the information you're looking for. Edit:
What's even better (IMHO) is to use the __construct() method to define the logic you want to use to create your object (instructions) rather than actually doing everything. So:
PHP Code:
<?php
class Customer{
private $name;
private $email;
private $whatever;
private $errorMessage;
private $queryResults;
// __construct() must always be "public" !!!
public function __construct($email){
if($this->findCustomerByEmail($email)){
$this->email = $email;
$this->setCustomerName();
$this->setCustomerWhatever();
}else{
$this->setErrorMessage();
}
}
private function findCustomerByEmail($email){
// use email to search DB and return customer row (if any)
// blahblahblah
$this->queryResults = $results;
}
private function setCustomerName(){
// use $this->queryResults to set name
// maybe something like $this->name = $this->queryResults['name'];
}
private function setCustomerWhatever(){
// etc.
}
private function setErrorMessage(){
// set error message
if($error){ return $this->errorMessage; }
}
}
?>