PHP Fluency
I know I’m late to the game here, but I finally got my cURL stuff working so that I can begin to see my way to launching all these sites. It took a lot of work to get there, –but I think it will be worth it, in terms of work down the road.
So, while browsing a pretty useful book, Object Oriented Programming with PHP (Hayder) a nicely chatty introduction to some pretty neat concepts and design patterns, I stumbled upon the concept of “method chaining.” Apparently, the proper term is “fluent interface.” Anyway, it answers the question I’ve had for a while: if chaining is done some easily in JQuery, why can’t it be done in PHP?
Well, the answer is that it CAN.
I’m reading up on it here:
[ N.B. There are two teeny mistakes in the code, the name of the object should be "$validate" not "$validation" AND "$value" should be "$this->value"]
$validation = new Validation();
$myvar = $_POST['somepostvariable'];
if ($validate->value($myvar)->required()->isInt()->execute())
public function isInt()
{
if (!is_numeric($value) || intval($value) !=$value)
{
$this->error_count++;
}
return $this;
}
”Otherwise, the second example works just fine.