Earlier quoted context omitted.
I'd just like to note that that is not a particularly OO solution. You've essentially created a namespaced function. While this is still preferable to a bare function in a heterogenous helpers function file, it's certainly not a pure OO way of accomplishing the encapsulation of the InputSanitizer.
And very fortunately so. 'Pure' OO is the madness that created Java. Encapsulation is overrated. So overrated that you need another fancy concept like 'dependency injection' when it just gets in the way. The static function is simple and because of that, it is good.
PHP Commandments
71–80 of 117 posts
Re: PHP Commandments
#72Are people still using PHP without frameworks these days?
The "cool kids" in PHP are using Laravel 4. It's a well made framework. I'm doing a REST API in it at work and the lack of mind share and docs is probably the worst part about it (it's still in beta to be fair). Most of the time I ended up reading the framework code. PHP leaves a lot to be desired though. It boggles my mind how developers who love what they do have the patience to stick with it. Example: Feature requ…
Re: PHP Commandments
#73Earlier quoted context omitted.
Yes it's slow in that it's a blocking call. Since it takes more than a fraction of a second put a message in the mail queue, it'll _feel_ slow.
I am trying to verify your claim: php -r '$s = microtime(1);mail("jcampbell1@gmail.com","test","text");printf("%d\n ms",(microtime(1)-$s)*1000);' > 20 ms 20 ms doesn't _feel_ slow. You spend far more time fetching the data and rendering the email.
The reason I assume that it has the feeling of being slow, from the applications I've had to clean up, is because many times there's processing happening right before the mail() function. So while, yes, its relatively fast the the total time is what feels slow.
And for comparison I've ran your commandline test as well with two of my cheap-o VPS instances, one of which is a Linode instance:
Linode: 50ms, 13ms, 14ms
Crappier VPS: 677ms, 149ms, 188ms
Re: PHP Commandments
#74I would add the following: General tips: * Understand how HTTP works (sounds trivial for a PHP developer, but at least here in Brazil, a huge portion doesn't do) * ALWAYS keep php.ini with production settings and replicate the same into your development environment (Vagrant is a great option here) * ALWAYS keep Apache or Nginx configs in sync among every environment * NEVER trust $_SERVER['REMOTE_ADDR'] to get client…
May I ask why not?
Re: PHP Commandments
#75Are people still using PHP without frameworks these days?
The "cool kids" in PHP are using Laravel 4. It's a well made framework. I'm doing a REST API in it at work and the lack of mind share and docs is probably the worst part about it (it's still in beta to be fair). Most of the time I ended up reading the framework code. PHP leaves a lot to be desired though. It boggles my mind how developers who love what they do have the patience to stick with it. Example: Feature requ…
(Haskell even does it as a function, and not as a macro.)
Re: PHP Commandments
#76Earlier quoted context omitted.
And very fortunately so. 'Pure' OO is the madness that created Java. Encapsulation is overrated. So overrated that you need another fancy concept like 'dependency injection' when it just gets in the way. The static function is simple and because of that, it is good.
tabbyjabby didn't say it's bad. They just said it's not OO.
I'm the one saying that strict OO is bad because it's verbose and its slower than the alternative.
Re: PHP Commandments
#77As for #6, I'd go as far as "NEVER use include, period." I've seen about 1 actual use case out of the bazillions out there; almost certainly, require() is the droid you're looking for. I'd also add a #10: Use E_ALL | E_STRICT , and don't ignore it. PHP is trying to tell you of many problems, shutting it up is not the right answer.
The reason this works is because -1 is 0xFFFFFFFF.
Re: PHP Commandments
#78Earlier quoted context omitted.
The "cool kids" in PHP are using Laravel 4. It's a well made framework. I'm doing a REST API in it at work and the lack of mind share and docs is probably the worst part about it (it's still in beta to be fair). Most of the time I ended up reading the framework code. PHP leaves a lot to be desired though. It boggles my mind how developers who love what they do have the patience to stick with it. Example: Feature requ…
Is anyone using Laravel 4 in production already? I thought it was still in beta.... I'm still messing with 3.
Re: PHP Commandments
#79I would add the following: General tips: * Understand how HTTP works (sounds trivial for a PHP developer, but at least here in Brazil, a huge portion doesn't do) * ALWAYS keep php.ini with production settings and replicate the same into your development environment (Vagrant is a great option here) * ALWAYS keep Apache or Nginx configs in sync among every environment * NEVER trust $_SERVER['REMOTE_ADDR'] to get client…
Don't use $_POST and $_GET globals directly May I ask why not?
Re: PHP Commandments
#80> NEVER hash passwords with MD5/SHA-1/Hash-of-the-day > PHPass will make life easy for yourself and keep your users' passwords secure. MD5/3DES/SHA-1 are relatively broken. But saying "use this magical library" is really far from a solution. Who's to say that that library won't be broken tomorrow and then someone else won't write an article next week saying "don't use PHPass!" Programmers just need to stay up-to-date…
MD5 for password storage isn't broken. It's still incomparably better than encrypting passwords. The problem is that it requires you to have a very strong password to start out with. This is 'acceptable' in that the security works with MD5, but 'unacceptable' in that it makes security much harder than it should be for no benefit. And it has always been this way, regardless of what people have thought about it in the…