Answer the question
In order to leave comments, you need to log in
How to organize OOP php
I'm making an access class to GET POST data, it's just like
<?
namespace core;
class Requests {
public static function GET($VarName, $Default = NULL)
{
return isset($_GET[$VarName]) ? $_GET[$VarName] : $Default;
}
<?
namespace contr;
use core\Requests;
class RequestPrepare extends Requests {
public static function correctData($data)
{
$data = strip_tags( (STRING)$data );
$data = mysql_real_escape_string ( trim( $data ) );
return ($data);
}
public static function correctInt($data)
{
$data = abs( (INT)$data );
return ($data);
}
$request = new contr\RequestPrepare ;
echo $request->correctInt( $request->GET('str') );
Answer the question
In order to leave comments, you need to log in
1. mysql_real_escape_string will not work without a connection resource.
2. forget about CAPSLOCK and read what camelCase is, your code will be more pleasant to read.
3. why static methods?
4. Read about the design pattern (template) - Singleton (singleton), usually the Request object is implemented in this way.
5. Why do we need inheritance in 2 classes?
6. instead of various correct* methods , I would rewrite the getter function like this:
const STRING = 1;
const INT = 2;
// ...
function get($value, $default = null, $type = self::STRING) {
if (! $value) {
return $default;
}
switch ($type) {
case self::STRING:
$value = addslashes(trim(strip_tags($value)));
break;
case self::INT:
$value = (int) $value;
break;
default:
throw new Exception('Unknown type');
break;
}
return $value;
}
it is not clear why you need this, but there are a couple of remarks if the method is declared as static then call it as static
public static function GET
Requests::GET('str');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question