NYCPHP Meetup

NYPHP.org

[nycphp-talk] Accessing Properties in PHP OOP

Joseph Crawford Jr. jcrawford at codebowl.com
Thu Aug 26 09:29:15 EDT 2004


why not just do

class client extends display {
then you can use $this->displaymethod
}

Joe Crawford Jr.


----- Original Message ----- 
From: "randal rust" <rrust at r2communications.com>
To: <talk at lists.nyphp.org>
Sent: Thursday, August 26, 2004 9:24 AM
Subject: [nycphp-talk] Accessing Properties in PHP OOP


> 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
> 
> _______________________________________________
> New York PHP Talk
> Supporting AMP Technology (Apache/MySQL/PHP)
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.newyorkphp.org
> 
> 



More information about the talk mailing list