News Feed
Sections
News Archive


Community Events
php|tek 2008 PHP Conference



feed this:

Ibuildings Blog:
Accessing object properties by reference
0 comments :: posted Monday May 05, 2008 @ 14:38:49
voice your opinion now!

On the Ibuildings blog today, Harrie Verveer has posted about an interesting quirk he found when working with objects and references:

PHP is a loosely typed language. Most of the time this is very useful because you as a programmer don't have to worry about typecasting: it's done for you. However, on some occasions this can cause some unexpected trouble. [...] In this blog I want to point out what can happen if you try to access object properties by reference when the object is not initialized.

His example shows the problem when it tries to grab a value from an array in a non-existent object by reference. It results in a dyanamically created object (of that type) with an empty array inside of it. It only works when you grab it by reference, but he shares a tip or two about how you can prevent hard to track down issues like this.

tagged with: property object reference find difficult issue


Cal Evans' Blog:
I called Zend_Jsonencode(), so WTH are all my properties?
0 comments :: posted Friday February 22, 2008 @ 12:10:00
voice your opinion now!

In dealing with a little JSON encoding and objects in a project of his recently, Cal Evans bumped against a problem when he was encoding an object and moving it back and forth between the back and front ends.

The problem is simple, JSON encode a PHP object and send it back to the front end. Sounds simple and the last 100 times I wrote this code it was simple. This time, I was too smart for my own good. Here's the scenario.

He illustrates his problem - the "dropping" of properties somewhere along the way - with a sample class that encodes the object and sends it along. He missed one key bit of information, though. His protected array of properties wasn't getting passed back out correctly and we're in the resulting JSON message. A quick hack of a getProperties() function call made this problem a thing of the past.

tagged with: zendframework json encode property getproperties problem

DevShed:
Keeping Track of Objects when Using Destructors in PHP 5
0 comments :: posted Wednesday January 30, 2008 @ 11:19:00
voice your opinion now!

Devshed continues their series looking at the use of destructors in PHP5 applications with part three, a method for keeping track of objects you've created during execution.

In this third part of the series, I'm going to show you how to retrieve some useful information about a specific object, including its properties and methods, prior to its being destroyed by the PHP parser via the implementation of a simple destructor.

Their new user class extracts the details about each of the objects right before they're destroyed via a call to get_object_vars and a loop to display the property and its value.

tagged with: php5 destructor object track property

Jan Kneschke's Blog:
typesafe objects in PHP
0 comments :: posted Tuesday February 20, 2007 @ 07:29:00
voice your opinion now!

Manfred Weber points out a new blog post from Jan Kneschke concerning the creation of and the idea of typesafe objects in PHP via doc-comments and the Reflection API.

From Jan:

I always disliked the way PHP handles Objects. There is no way to assign a type to properties. Validators have to be glued against the fields externally and you can't just generate a Object-Description (like WSDL) from a object either.

Because of this he's looked into an alternate solution - the typesafe objects. Since, by defauly, PHP's addition of object properties is pretty freeform, making things typesafe is a little difficult. His suggestion, though, uses a combination of comments in the code (declaring what the type of the property should be) and the Reflection API built in to PHP to "look back" at the comments and ensure the type of the property is correct. He even includes examples - a simple one about throwing an error, generating XML this way, and making safe encoded SQL statements.

tagged with: typesafe object reflection comment type property typesafe object reflection comment type property


code book conference security releases release ajax zend PHP5 database application developer framework zendframework PEAR pecl job package cakephp mysql

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