[nycphp-talk] Accessing Properties in PHP OOP
randal rust
rrust at r2communications.com
Thu Aug 26 09:24:18 EDT 2004
I am building an application as an exercise in moving from procedural
programming to OOP.
I have the following classes...
class_display.php
class_validator.php
class_client.php
What I would like to do is clean my code up a little. Within
class_client and class_validator, I access and modify properties of
class_display by declaring 'global $display.'
I don't think this is right, but I can't seem to find another way that
works.
Code snippets are posted below. TIA.
//code for class_display
class Display {
var $errors=false;
var $errorM;
var $success=false;
var $successM;
var $display=true;
}
//code snippet from class_validator
class Validator {
var $type;
var $value;
var $pass;
function validateAlpha($value){
$value=trim($value);
$pass=preg_match('/^[a-zA-Z-]+$/', $value);
return $pass;
}
}
//code snippet from class_client
class Client {
function clientNameCheck($value){
global $display;
global $validator;
$test=$validator->validateMixed($value);
if(!$test){
$display->errors=true;
$this->clientNameEM='<p class="error">ERROR: Client name is not
valid.</p>';
return false;
}
}
//begin add method
function addClient(){
//call to other classes
global $conn;
global $validator;
global $display;
//validate user input
$this->clientNameCheck($this->clientName);
}
//end add method
}
--
Randal Rust
R.Squared Communications
http://www.r2communications.com
Digital Design for Bricks-and-Mortar Businesses
More information about the talk
mailing list