Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Nikita Popov's Blog:
Scalar type hinting is harder than you think
Mar 07, 2012 @ 16:03:47

In this new post to his blog Nikita talks about scalar type hinting and why it's harder than most people think to accomplish.

One of the features originally planned for PHP 5.4 was scalar type hinting. But as you know, they weren’t included in the release. Recently the topic has come up again on the mailing list and there has been a hell lot of discussion about it. Yesterday ircmaxell published a blog post about his particular proposals. The reactions on reddit were mixed. On one hand it is clear that people do really want scalar type hints, on the other hand they didn't seem to like that particular proposal.

He gets into some of the details of some of the current proposals and their problems like the strict versus loosely-typed nature of PHP and type hinting that was included but not enforced. One he does like, however, is one based on casting - how the variable ends up being cast rather than the specific type it is when it comes into the function/method. This one still has its flaws, so he suggests another method - weak type hints but with stricter input validation (without casting). He also briefly mentions something called "box based type hinting" that would allow users to define their own hinting rules.

Don't worry - code examples (pseudo-code obviously) are included for each of these proposals to help you understand the differences.

tagged: type hinting static strict looselytyped proposal scalar

Link:

Tobias Schlitt's Blog:
Funny speed considerations
Oct 01, 2007 @ 17:04:00

Tobias Schlitt offers a helpful hint or two for "speeding up" your application in the form of comparison operators.

The fact that type save comparisons (ala ===) are faster in PHP than the normal comparison operator (ala ==). The reason for this is simply, that PHPs loosly-typed-ness-auto-cast-code is not even touched with ===

He also points out an interesting condition that saves a bit of computing time - comparing the isset() of a variable to true over the count() to zero. Some of his benchmarking (code) shows this in action.

tagged: speed comparison operator looselytyped speed comparison operator looselytyped

Link:

Tobias Schlitt's Blog:
Funny speed considerations
Oct 01, 2007 @ 17:04:00

Tobias Schlitt offers a helpful hint or two for "speeding up" your application in the form of comparison operators.

The fact that type save comparisons (ala ===) are faster in PHP than the normal comparison operator (ala ==). The reason for this is simply, that PHPs loosly-typed-ness-auto-cast-code is not even touched with ===

He also points out an interesting condition that saves a bit of computing time - comparing the isset() of a variable to true over the count() to zero. Some of his benchmarking (code) shows this in action.

tagged: speed comparison operator looselytyped speed comparison operator looselytyped

Link:


Trending Topics: