Reply to Object Oriented PHP

Your name:

Reply:


Posted by Angelos on 11/23/05 17:29

Hello again,

I have written three classes : validate.class.php,
report_handler.class.php, sentry.class.php.

The problem is that the "validate" class uses the "reporting" class and
the "sentry" uses the "validate" that uses the "reporting".

So I end up having something like that inside sentry.class.php:
$validate->report->getReport();

But although that's working... it doesn't seem to be really OO :p

So can you tell me what I can do ?

If what I am saying doesn't make any sense at all... let me know and I
will try to explain it better.

Bellow I have some snippets from each class that may help you to
understand what I am trying to do.
********************************************************************
class report_handler {
....
/* This Function populates the array with reports (ERRORS,MESSAGES)
* Syntax: setReport($reportType,$string)
*/
function setReport($reportType,$string='') {
if($this->validateReportTypes($reportType)) {
$this->counter++;
$this->report[$this->counter] = array( 'category' => $reportType,
'description' => $string);
}
else
echo "Report type '".$reportType."' is not valid";
}
/* Output the report to the user
*/
function getReport() {
if(is_array($this->report))
{
foreach($this->report as $i => $value)
{
echo "<pre>".
$value['category'].': '.
$value['description']
."</pre>";
}
}
}
....
}
/*****************END of class report_handler********************/

class validate {

function validate()
{
$this->report = new report_handler();
}

function checkEmail($email)
{
// checks proper syntax
if(
!preg_match('/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/',
$email))
{
$this->report->setReport('Error','Syntax Error');
return false;
}
....
}
}
/*****************END of class validate ********************/
class sentry {
var $user_id;
var $session_timeout;

function sentry()
{
$this->report = new report_handler;
}
....

function validateLoginForm()
{
$validate = new validate();
if($validate->checkEmail($_POST['email']))
{
$this->loginUserName = $_POST['email'];
$this->loginPassword = $_POST['passwd'];
return true;
}
else
{
$validate->report->getReport();
return false;
}
}
.....
}
/*****************END of class sentry********************/




Thanks a lot for reading and for any help you may provide.
Angelos.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация