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

Stoyan Stefanov's Blog:
JavaScript-style object literals in PHP
March 25, 2011 @ 09:02:59

Stoyan Stefanov has a new post to his blog looking at bringing something to PHP that Javascript developers have always had - object literals. These literals allow you to assign object properties at definition time instead of the usual PHP method of adding them either in the class definition or after the object exists.

Stoyan starts with an example of the object literals on Javascript and shows how it's (sort of) possible to replicate that wit type casting an array to an object in PHP. The tricky part comes in when you try to recreate the method handling JS gives in objects. Closures in PHP 5.3 comes close, but there's a few things he points out that just won't work the same way.

You can simulate some of this with __call method handling in a base "JSObject" class. For more details on his work bringing Javascript over to the world of PHP, check out his presentation from this year's ConFoo conference.

1 comment voice your opinion now!
javascript object literals tutorial closure call


WebReference.com:
The Building Blocks Data Types, Literals, Variables, and Constants - Part 2
January 22, 2007 @ 09:52:00

WebReference.com has posted part two in a series looking at the "building blocks" that make up PHP and its use. This time, it's a look at the containers for your data - the data types, literals, variables, and constants.

They go through each, explaining what they are, how they're used and when you'd want to use them in your code. They explain the data types and how those fit with each "container" and some basic things like valid names and how to assign things correctly.

They even get get into working with variables from GET and POST requests as well as working with the scope of variables and getting the metadata about them (is it an integer? is it empty?)

0 comments voice your opinion now!
building blocks datatypes literals variables constants tutorial building blocks datatypes literals variables constants tutorial



Community Events





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


opinion security voicesoftheelephpant introduction series tool framework symfony composer community podcast language release library laravel package update install interview version

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