PHP Classes

filter_var as _set and _get() methods

Recommend this page to a friend!

      Simple PHP PDO MySQL  >  All threads  >  filter_var as _set and _get() methods  >  (Un) Subscribe thread alerts  
Subject:filter_var as _set and _get() methods
Summary:Suggestion to use _set and _get method with filter_var
Messages:2
Author:Daniel Mulder
Date:2014-12-06 19:12:08
 

  1. filter_var as _set and _get() methods   Reply   Report abuse  
Picture of Daniel Mulder Daniel Mulder - 2014-12-06 19:12:08
Hi,

Great work on this class. Very useful. Although I'm not a programmer by trade but I am working on an app for myself. The classes I made are developing some nicely and getting better every time. I use filter_var with the _set and _get method like this:

public function __set($Property, $Value)
{
if ($Property == 'Username') {
$this->username = filter_var($Value, FILTER_SANITIZE_MAGIC_QUOTES);
}
if ($Property == 'Password') {
$this->username = filter_var($Value, FILTER_SANITIZE_MAGIC_QUOTES);
}
if ($Property == 'User_id') {
$this->user_id = filter_var($Value, FILTER_SANITIZE_NUMBER_INT);
}
}

I am thinking of incorporating this as replacement for the string functions. This should make it compacter and more reliable? Or am I not seeing the big picture?

Also thinking about adding a inaccessible method to set the hashed password property as magic _set _get method. Would be nice to have something like this as an inaccessible magic property:

_set($Password) {
if( !isset( $this->cost ))
{
$cost = 10;
do {
$cost++;
$start = microtime(true);
password_hash("testhestring", PASSWORD_BCRYPT, ["cost" => $cost]);
$end = microtime(true);
} while (($end - $start) < $timeTarget);
$this->hash_base_rate = $cost
}
else { password_hash( "testhestring",
PASSWORD_BCRYPT,
["cost" => $this->hash_base_rate]);
}
}

Or is this silly of me?

Thanks and cheers!

  2. Re: filter_var as _set and _get() methods   Reply   Report abuse  
Picture of Bennett Stone Bennett Stone - 2014-12-11 17:01:04 - In reply to message 1 from Daniel Mulder
Thanks Daniel!

You could certainly add that to the class itself, however, I intentionally omitted bits to handle password encryption and other methods of encryption since that is most frequently done within other parts of an application (same regarding the __set properties that are conditional for the different types of data as those also vary wildly amongst different applications).