News Feed
Sections




News Archive
feed this:

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

Samantha Quinones:
Juggle Chainsaws, Not Types
November 22, 2013 @ 09:25:33

Samantha Quinones has a new post today about something that has been known to trip up both new and experienced PHP developers - PHP's dynamic type juggling.

No matter how popular an activity it is, I really don't like to bash on PHP. Every language has its flaws when you look closely enough, and if PHP wears its idiosyncrasies a little closer to the surface than most, I think it makes up for it in other ways. PHP's handling of types, however, is confusing at best and at worst completely deranged.

She goes on to talk about the issues with type comparisons and how much trouble using the "==" (double equals) versus the "===" (triple equals) can potentially cause. While it's easier for new PHP developers to get caught by this issue, even experienced devs might miss it. She gives an example of a time in her own development involving the comparison of strings against constants and in_array's non-string type comparisons.

0 comments voice your opinion now!
type juggling strict loose comparison inarray

Link: http://www.tembies.com/2013/11/juggle-chainsaws/

Nikita Popov's Blog:
Scalar type hinting is harder than you think
March 07, 2012 @ 10: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.

0 comments voice your opinion now!
type hinting static strict looselytyped proposal scalar


Lorna Mitchell's Blog:
Declaring Static Methods in PHP
December 10, 2010 @ 08:40:45

Lorna Mitchell has a new post to her blog today talking about static methods and how to use them correctly in your code (as discovered accidentally in her own code).

I was confused recently to realise that I had accidentally called a static method in PHP dynamically from another part of my code; I expected PHP to output warnings when this is done. On closer inspection I discovered that: static functions can be called dynamically and dynamic functions generate an E_STRICT error if called statically.

She illustrates with some sample code that, when run with E_ALL and E_STRICT throws a warning from the strict side about calling a non-static method statically. She also talks about why it throws this warning for the non-static call on a static method. She also explains why, when a static method is called dynamically, no warning is thrown.

0 comments voice your opinion now!
declaring static method warning strict


Matthew Turland's Blog:
The Yin and Yang of Typing
February 01, 2008 @ 11:58:00

A little while back Matthew Turland posted about something that some developers moving over to PHP from more strict languages have an issue with - variable typing - and how its evolved in languages over time.

Without a little background in programming languages or computer science in general, it's entirely possible that typing systems are not something that have crossed your mind. I thought I'd take a blog entry to share some of my thoughts on how it's affecting the creation and evolution of languages.

He walks through history a bit, mentioning C, Java, Python and PHP and how they differ in their default type handling. He especially focuses on the "blurred line" between strong and weak typing and how some if offers special features to the language that uses the method.

0 comments voice your opinion now!
typing strong weak strict dynamic java python c


Clay Loveless' Blog:
PHP and JSON Cut #987
March 01, 2007 @ 08:43:00

In a new post today, Clay Loveless talks about some issues he's been having with PHP and JSON, specifically with the JSON encoding method in PHP 5.2.1.

As of PHP 5.2.1, json_decode() no longer follows the published standards for JSON-encoded texts. Why not? For no reason other than the convenience of those ignorant of JSON standards.

His complaint stems from the results of a vat_dump statement - prior to this version it would give a NULL, but now it returns a "bool(true)" value back, resulting in some breakage of previous scripts. He spends the rest of the post explaining his voyage through the JSON world and how things are supposed to behave. He also digs a little deeper into the var_dump issue and why he thinks it's such a bad thing.

0 comments voice your opinion now!
json vardump null true strict adhere extension standard json vardump null true strict adhere extension standard


Felix Geisendorfer's Blog:
How-to Use Html 4.01 in CakePHP 1.2
February 22, 2007 @ 08:35:00

Felix Geisendorfer has a "quick hit" tip posted to his blog today on using HTML 4.0.1 in your CakePHP 1.2 installation.

This is just a little tip for those of you who dislike their xhtml to end up as tag soup and still prefer to send out Html 4.01 strict. Here is how to make all helper functions in Cake 1.2 output Html 4.01 compliant markup instead of xhtml.

The helper he's created just loops through the entire $tags array and does a replace on the greater-than sign to add a slash to make it compliant.

0 comments voice your opinion now!
cakephpframework html xhtml helper strict cakephpframework html xhtml helper strict


SitePoint PHP Blog:
How strict is your dynamic language?
July 27, 2006 @ 06:00:58

Harry Fuecks wonders in this new post on the SitePoint PHP Blog "how strict is your dynamic language?"

Considering the "big four" dynamic, procedural languages; Perl, Python, PHP and Ruby, to an extent they're much of a muchness, offering only small variations on the same theme (ignoring PHP's lack of support for functional-style programming). But sometimes little things make a big difference, and perhaps most of all when your code is given input to handle which it wasn't designed for. Knocked up a simple example to compare them in this area...

He compares four languages - Perl, PHP, Ruby, and Python - by giving, for each, code examples and what the output would be, including what would error out. These examples help to illustrate his final points:

  • where is the point when a fatal error should be raised?
  • what is it the languages should actually complain about?

0 comments voice your opinion now!
strict dynamic language errors perl python ruby compare strict dynamic language errors perl python ruby compare



Community Events





Don't see your event here?
Let us know!


deployment library interview conference voicesoftheelephpant podcast community release framework zendserver series symfony introduction developer api tips list language bugfix laravel

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework