News Feed
Jobs Feed

News Archive
feed this:

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

Derick Rethans:
Contributing Advent 1 Xdebug and hidden properties
December 02, 2013 @ 09:16:50

As a part of his "Advent Contribution" series Derick Rethans has posted about an update to XDebug that fixes a bug reported around hidden properties.

This first contribution is for bug #987: "Hidden property names not shown". In PHP it is possible to convert an array to an object. [...] Xdebug's standard HTML var_dump() as well as the CLI, the coloured CLI and the debugger interface DBGp all suffered from the same issues that numerical properties were not showing in output.

With the committed fix the output of the var_dump now shows these special property names with curly braces around them and makes them available via the property_get method. If you're interested in the actual commit, you can check it out here.

0 comments voice your opinion now!
advent contribute hidden properties xdebug vardump propertyget

Configuration is code
November 20, 2013 @ 10:54:12

In this recent post to Giorgio Sironi talks about how, despite it commonly not being intended this way, configuration files usually end up being "code".

You start out with a simple .ini file [and] after a while, you customize its values by deployment environment. [You] then substitute values in it, to remove duplication or substitute constants, for that matter. Finally, you start supporting dynamic values, because this gives you more flexibility. The thesis of this article is that an efficient solution for supporting the more complex use cases of configuration can be found, without piling up proprietary or open source libraries to parse more and more complex configuration files. This solution, namely, is to use a more powerful language: your own dynamic programming language.

He looks at the "back in the day" configuration types that Java frameworks used - mostly XML files with a tight coupling to the servlet using it. He steps back a bit and looks at what he calls the "properties of code" and relates it to this dynamic language for configuration he's been talking about.

0 comments voice your opinion now!
configuration dynamic language properties


Chris Hartjes' Blog:
Metatesting Testing Constructors
April 06, 2012 @ 08:28:00

In a new post to his blog Chris Hartjes, promoter of all things testing, looks a a method for testing constructors - an effective way to validate the things that happen when your objects are generated.

If you have a PHP application that makes heavy use of objects (which is probably 95% of you reading this) then you will have objects with constructor methods in them. It is also very likely that there is some stuff going on in those constructors. So how do you test things like this?

He includes a sample constructor that creates a container, pulls out some configuration values and reassigns them to class properties. He first tests that these properties have been set correctly by mocking out the object and overriding the configuration settings in the (dependency injection) container.

0 comments voice your opinion now!
testing constructors unittest mock object properties

Jani Hartikainen's Blog:
Creating a simple abstract model to reduce boilerplate code
March 02, 2009 @ 12:07:54

In a new blog post Jani Hartikainen shows how to create an abstract model that you can build on when you need to make a dynamic model for your framework application.

In a usual scenario involving models in PHP, you will have some repeating things: You will usually need getters and setters for the model's properties, you will need to be able to construct the model from an SQL query or such, and you'll also need to write SQL queries for the models.

He builds up the three different parts of the abstract model - the getters/setters, fleshing out the model by defining its properties from array values and creating some dynamic SQL (based on property names).

0 comments voice your opinion now!
biolerplate model dynamic framework getter setter properties sql

Tobias Schlitt's Blog:
Reflecting private properties
February 15, 2008 @ 12:02:00

Tobias Schlitt has posted a handy tip about using the Reflection API in PHP5 - specifically its accessing of private properties in a class.

I recently stumbled over reflecting private properties in PHP again. As you might know, this was not possible until now and if you tried this [code] PHP thanked it to you with this [error that is cannot access a non-public member].

He notes that, while the behaviour is correct, it still makes things like metaprogramming impossible. So, what's a developer to do? Patch it of course! Tobias and Derick Rethans persuaded two other developers (Derick and Marcus Borger) to include a patch that allows the Reflection API to see these private variables.

To make it work, you have to use the setAccessible method on the Reflection object to set which of the properties you want to be able to get at.

1 comment voice your opinion now!
reflection api setaccessible private properties

Stefan Mischook's Blog:
A Question about object properties in PHP Classes
December 07, 2007 @ 14:33:00

Stefan Mischook shares a little question and answer he had recently concerning object properties in PHP.

The question asked about accessing properties outside the class and/or defining them as protected/private to prevent it. Stefan's response was basically:

Many OO techniques are designed for situations where you will have more than one programmer involved, now or later. By declaring variables as protected or private, you are adding security to the code base by forcing the use of getter and setter methods where you can control how objects are used.
0 comments voice your opinion now!
properties classes object private protected properties classes object private protected

Tobias Schlitt's Blog:
Virtual Properties
May 10, 2007 @ 07:57:00

In response to this previous post from Jeff Moore, Tobias Schlitt shares some of his own comments on the subject - mainly that he wholeheartedly agrees.

The usage of interceptors (__get()/__set()/__isset()/__call()) makes your API a lot more readable and comfortable, while maintaining the purpose behind getters and setters: Checking the correctness of values assigned to a property and wrapping around retrieval mechanisms for a property. I personally call the way of maintaining value-correctness for properties through interceptors virtual properties, which fits quite nice I think.

Tobias gives an example of what he means by these "virtual properties" with an illustration from something widely used on the eZ Components libraries - comparing one method of setting text to an object to another (just setting versus the wrappers).

0 comments voice your opinion now!
virtual properties setter getter interceptor ezcomponents virtual properties setter getter interceptor ezcomponents

Jeff Moore's Blog:
Let Your Properties be Properties
May 10, 2007 @ 07:11:45

In a recent post to his blog, Jeff Moore advocates the philosophy that, in your OOP application development, you should "let your properties be properties".

Some times there are some ancillary methods to deal with unsetting, checking for existence, setting via an array, or dealing with references in PHP 4. They can really clutter up the definition of a class. That's not good.

[...] I think the idea is to make the class extensible. But PHP is really ok with just setting new properties on a class. So why not just do this?

He argues that getters and setters in a class are less useful than just setting the property yourself. Using the property name as part of the interface, though (like getting the $obj->foo value with $obj->getFoo) is stil clean enough to be useful.

0 comments voice your opinion now!
properties class oop setter getter object properties class oop setter getter object

Mike Wallner's Blog:
__get() and array rumors
August 21, 2006 @ 07:49:03

In a brief new post, Mike Wallner talks about some of the discussion surrounding overloaded array properties lately and something he's discovered about it.

As arrays are the only complex types that are passed by value (resources don't really count here) the solution to described problem is simple: use an object; either an instance of stdClass or ArrayObject will do well, depending if you want to use array index notation.

He includes two code examples, one just trying to overload it in a class with __get (yielding an error) and the other using the constructor to pass an ArrayObject out first, allowing for error-free assignment.

0 comments voice your opinion now!
arrayobject overload array properties get construct arrayobject overload array properties get construct

Classes as PHP Functions
August 09, 2006 @ 05:49:25

Continuing on in their "PHP functions" series today, DevShed has posted this next step up the ladder, getting more advanced with the functions they're working with. This time, there's a focus on functions inside classes and creating the classes around them (a sort of introduction to object-oriented programming).

Continuing our PHP functions article, we move on to creating classes. Let me say right at the start that you can write perfectly effective and useful PHP code without creating classes or going into object oriented programming. Object oriented programming can be very powerful and PHP programmers are increasingly taking advantage of these capabilities, which have been greatly expanded since PHP4.

They start with the creation of a simple class - a human class with two $legs and two $arms. They show a simple display of this data and add another attribute to the class, one for hair color. They then capture the output they've been creating inside a function, report, and show how to execute it. Finally, they show how to use the special function that runs when the object is created - the constructor.

0 comments voice your opinion now!
classes functions methods properties tutorial part2 classes functions methods properties tutorial part2

Community Events

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

threedevsandamaybe code language facebook hack package framework overview opinion symfony2 podcast security introduction hhvm unittest install application release component composer

All content copyright, 2014 :: - Powered by the Solar PHP Framework