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

Matthias Noback:
Objects should be constructed in one go
Jul 17, 2018 @ 14:21:04

In a new post to his site Matthias Noback makes an interesting suggestion about working with objects in PHP: that they should all be made in one, and only one, place.

Consider the following rule: "When you create an object, it should be complete, consistent and valid in one go."

It is derived from the more general principle that it should not be possible for an object to exist in an inconsistent state. I think this is a very important rule, one that will gradually lead everyone from the swamps of those dreaded "anemic" domain models. However, the question still remains: what does all of this mean?

He shares an example of an object (GeoLocation) that can be created with only the latitude value but points out that this leaves it in an invalid state. He updates this example to show a more complete implementation, one that prevents an object with partial setup from happening. He then talks about the aggregation of child entities and a "paper" metaphor. This metaphor - imagining a "paper purchase order" - helps him wrap his head around the structure of the objects and how they interact.

tagged: object creation construct child aggregate tutorial

Link: https://matthiasnoback.nl/2018/07/objects-should-be-constructed-in-one-go/

Joshua Thijssen:
Internal PHP function usage: revisited
Aug 06, 2014 @ 16:53:34

Joshua Thjissen has revisited some of his PHP internal function statistics, an update from this previous post with some results showing the most (and least) used internal PHP functions in several large projects from GitHub.

A lot of people are asking about functions like isset, empty, print, echo etc, as they are not present in the current result list. The thing is, is that these are not really functions, but language constructs. This means that PHP treats them a bit different than normal functions, and this results sometimes in seemingly “strange” behaviour when trying to use them like regular functions.

He's updated his results, though, to reflect the usage of these "functions" and shared the numbers. Not surprisingly, these constructs show up pretty highly in the new "top 22" list he's produced. With the inclusion of the constructs, the number one item on the list is now "isset" by a very large margin. The full results can be found in this gist.

tagged: internal function usage statistics github revisit construct language

Link: https://www.adayinthelifeof.nl/2014/08/05/internal-php-function-usage-revisited/

Martynas Jusevicius' Blog:
Method overloading in PHP 5
Dec 02, 2008 @ 16:28:50

Martynas Jusevicius has a new post looking at method overloading in PHP5 - a workaround to make it possible at least.

Method overloading (a feature of object-oriented programing which allows having several class methods with the same name but different signatures) is not implemented in PHP, which is a drawback compared to Java. However, PHP 5 provides a way to imitate overloading by catching calls to "inaccessible methods" with magic method __call.

In his example he uses __call to route the request to the correct version of the constructor (__construct0 or __construct1) based on the number of arguments passed in

tagged: method overload php5 construct call magic function route

Link:

Brian Moon's Blog:
Short Array Syntax for PHP
May 29, 2008 @ 16:13:00

There's been some talk floating around about a proposed additional syntax for creating arrays in PHP. Brian Moon sums it up nicely in a new post to his blog.

So, I was asked in IRC today about the proposed short array syntax for PHP. For those that don't know, I mean the same syntax that other languages (javascript, perl, python, ruby) all have. [...] It just feels like a good addition to the language. It is common among web languages and therefore users coming into PHP from other languages may find it more comfortable.

He compares it with other data type creation in PHP (you don't call int() to make an integer, so why call array() to make an array). However, according to a post from the internals mailing list, we might not be seeing this any time soon.

tagged: short syntax array function integer string language construct

Link:

PHP-Coding-Practices.com:
How Table Migrations In CakePHP 1.2 Can Save Your Life
Jul 03, 2007 @ 19:36:07

On PHP-Coding-Practices.com, Tim Koschuetzki has posted a new tutorial that just might save your life - well, at least the life of your CakePHP application - using table migrations.

Migrations are a wonderful technique to keep your database in sync with your code. When working on a project as a team, migrations can save your life. Please join me and get a quick introduction to migrations in CakePHP and become a happier coder.

He starts by explaining what migrations are (yml files that contain database construction/destruction information), how to execute them in your application, and how to construct your own.

tagged: migration table cakephp database construct destruct yml migration table cakephp database construct destruct yml

Link:

PHP-Coding-Practices.com:
How Table Migrations In CakePHP 1.2 Can Save Your Life
Jul 03, 2007 @ 19:36:07

On PHP-Coding-Practices.com, Tim Koschuetzki has posted a new tutorial that just might save your life - well, at least the life of your CakePHP application - using table migrations.

Migrations are a wonderful technique to keep your database in sync with your code. When working on a project as a team, migrations can save your life. Please join me and get a quick introduction to migrations in CakePHP and become a happier coder.

He starts by explaining what migrations are (yml files that contain database construction/destruction information), how to execute them in your application, and how to construct your own.

tagged: migration table cakephp database construct destruct yml migration table cakephp database construct destruct yml

Link:

PHP 10.0 Blog:
We are doomed! (and Ticks in PHP)
Jun 20, 2007 @ 15:29:00

In this new post to the PHP 10.0 blog, Stas mentions the "impending doom" of PHP that's been going around the community, including in this post on the TechRepublic site.

He does, however, branch off into something much more interesting that seems to be somewhat ignored by developers - the use of ticks on their code:

This is something named "ticks" - I wonder how many of the PHP developers heard about it and of those how many actually used it. Could it be used for offloading long-running I/O-bound tasks or grouping them together (e.g. so we could wait for DB and HTTP in parallel and not sequentially)? Would there be any use at all for such functionality and if so - how it's supposed to work? I.e. how would you know it's done and how you would collect and use the results?

It's suggested in the comments that it could be used for any kind of application that might need the pseudo-multithreading it offers (including something like scripts needing multiple TCP connections).

tagged: doom tick multithread declare construct doom tick multithread declare construct

Link:

PHP 10.0 Blog:
We are doomed! (and Ticks in PHP)
Jun 20, 2007 @ 15:29:00

In this new post to the PHP 10.0 blog, Stas mentions the "impending doom" of PHP that's been going around the community, including in this post on the TechRepublic site.

He does, however, branch off into something much more interesting that seems to be somewhat ignored by developers - the use of ticks on their code:

This is something named "ticks" - I wonder how many of the PHP developers heard about it and of those how many actually used it. Could it be used for offloading long-running I/O-bound tasks or grouping them together (e.g. so we could wait for DB and HTTP in parallel and not sequentially)? Would there be any use at all for such functionality and if so - how it's supposed to work? I.e. how would you know it's done and how you would collect and use the results?

It's suggested in the comments that it could be used for any kind of application that might need the pseudo-multithreading it offers (including something like scripts needing multiple TCP connections).

tagged: doom tick multithread declare construct doom tick multithread declare construct

Link:

YoungCoders.com:
The PHP Construct You've Never Used
Sep 19, 2006 @ 12:38:14

As pointed out by the Zend Developer Zone today, there's a useful forum post over on the YoungCoders.com website that talks about very useful feature that some PHP developers just don't use - ticks.

You've probably never used it, never saw it, or never found a practical use for ticks, a underused and powerful feature of PHP that allows you to implement exceptions in PHP4, do intensive debugging and profiling, check database connections, turn PHP into an event driven language, or harness complex control over your code.

The post talks about what ticks are, how to enable them, and a few examples of how to use them. Check out more about them in this page on the PHP Manual.

tagged: ticks construct tutorial concept example declare ticks construct tutorial concept example declare

Link:

YoungCoders.com:
The PHP Construct You've Never Used
Sep 19, 2006 @ 12:38:14

As pointed out by the Zend Developer Zone today, there's a useful forum post over on the YoungCoders.com website that talks about very useful feature that some PHP developers just don't use - ticks.

You've probably never used it, never saw it, or never found a practical use for ticks, a underused and powerful feature of PHP that allows you to implement exceptions in PHP4, do intensive debugging and profiling, check database connections, turn PHP into an event driven language, or harness complex control over your code.

The post talks about what ticks are, how to enable them, and a few examples of how to use them. Check out more about them in this page on the PHP Manual.

tagged: ticks construct tutorial concept example declare ticks construct tutorial concept example declare

Link:


Trending Topics: