开发者

Could someone critique my PHP register/validation classes?

http://pastie.org/931617 is a link to the source code. If there is a better way to do this, let me know.

One thing I'm unsure about, is the way I handle child/parent constructs in the validation classes towards the bottom.

Thanks.

Ok, I took your advice using an associative array. Now, I just toss the $_POST variable to my construct. How does this look - http://pastie.开发者_运维问答org/931715


You handle constructs correct.

Very long lists of arguments are good in strongly typed languages such as C++, but are not very convenient and safe for PHP. My advice is to use associative arrays.

function __construct(&$args)
{
    parent::__construct($args);

    $this->contactphone = $this->get($args, 'contactphone'); // check if $args['contactphone'] is specified, otherwise return null
    $this->firmname = $this->get($args, 'firmname');
    // ...
}

Usage:

$args = array(
'username' => $username, 
'password' => $password, 
'confirmpassword' => $confirmpassword
);
$e = new EmployerRegister($args);

Your benefits:

  1. You do not need to remember exact order of arguments. Create array of args in any order. Less bugs. Less typing.

  2. Some arguments may be empty, so no need to send them. Better performance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜