News Feed
Jobs Feed
Sections




News Archive
feed this:

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

VG Tech:
Comparing Your Privates in PHP
March 19, 2014 @ 09:56:33

In a new post to their blog, the VG Tech folks talk about "comparing your privates" with a "hidden" feature of PHP. Don't worry, they're referring to private class properties on object instances here...

I was going to compare several private properties between to objects and started making a piece of code to perform the actual comparison using getters for the properties. I felt the approach sucked, and started looking into alternatives way to do this.

He shares what the current PHP documentation shares about comparing objects, but neither of them take private properties into account. He remembers, however, that object visibility is at the class level not instance level, allowing two object instances of the same class to have access to all properties of the other, regardless of exposure level. He includes a code snippet showing how to use this to compare those private properties.

0 comments voice your opinion now!
private comparison object instance class

Link: http://tech.vg.no/2014/03/14/comparing-your-privates-in-php/

Qandidate.com:
Using Satis for fast and reliable software deployment
December 05, 2013 @ 11:57:32

One of the major recent advancements in the PHP ecosystem has been the use of Composer (and the Packagist service) for package and dependency management. Unfortunately, this default setup comes with one big limitation - if the Packagist or Github are unavailable for some reason, your Composer install will fail, possibly leaving you dead in the water. So, what can you do to help? On the Qandidate.com blog today they introduce you to Satis and how to integrate it into your deployment process.

If you're familiar with Composer you know it can be slow and sometimes unreliable when one or more packages are not available. Every time you run composer update Composer will access Packagist to check for new versions of the packages you use. When it finds new releases it will access GitHub, BitBucket (or wherever the packages are hosted) to download your packages.

Satis is a "private Packagist" and provides the data Composer needs to fetch and integrate either your internal packages or mirrors of external ones you've created. They help you get it installed, configured and show how to build and serve up the information via PHP's own built-in web server. They also touch on a few other related points - the speed of Satis, reliability and some concerns around securing your installation.

0 comments voice your opinion now!
satis introduction packagist composer alternative private package

Link: http://labs.qandidate.com/blog/2013/12/05/using-satis-for-fast-and-reliable-software-deployment/

Christian Weiske:
PHP Cannot access property started with '\o'
November 08, 2013 @ 09:59:13

Christian Weiske had an interesting situation pop up in one of his applications around a call to a variable with an interesting name.

Some days ago I saw the following fatal error for the first time in my life:

Fatal error: Cannot access property started with 'o' in file.php

After some debugging, I found out that the source of the error was not some strange BOM or UTF-8 characters in PHP source code files. No, it was a combination of protected class properties, object-to-array casting and automatic template property mappings.

As it turns out, there was a change in how object-to-array casting was done in PHP 5.3 that made this break (related to things appended to private and protected variable names). He includes a bit of sample code to illustrate the problem - a simple class converted from object to array with direct casting. He does point out that it doesn't happen with get_object_vars, though, as that doesn't do the casting, just extraction.

0 comments voice your opinion now!
class property special character private protected casting

Link: http://cweiske.de/tagebuch/php-property-started-nul.htm

7PHP.com:
Auto Generate Properties Dynamically For Your Classes Using Magic Methods & Reflection
October 28, 2013 @ 12:57:14

Accessing private class properties via getters and setters is a pretty standard way to write your applications. Unfortunately it can be time consuming to write them for every property your class may have. On 7PHP.com Khayrattee Wasseem has a few ideas (including using PHP's own Reflection functionality) to dynamically create them.

When coding a project, at times (or most of it?) some classes might have more than 3 fields (for whatever reason it suits you). So instead of each time writing and repeating setters and getters (accessor methods), I would like to have a piece of reusable code for all my classes without me ever writing a single line of code for accessors. ('ever' as in 'very very rarely'). Now, we also have to take into consideration that some fields might be only get-able or only set-able - (our re-usable piece of code should cater for this)

He shows two different methods to accomplish this kind of dynamic access, one using traits and the other using normal class inheritance. HE includes the code illustration each solution and talks a bit at the end of each section of why that method might be better than the other.

0 comments voice your opinion now!
reflection getter setter private property tutorial trait inheritance

Link: http://7php.com/magic-dynamic-properties/

Marco Pivetta:
Accessing private PHP class members without reflection
August 15, 2013 @ 12:53:55

Marco Pivetta has posted about an interesting trick you can do with closures in PHP related to accessing private properties inside classes.

A couple of weeks ago I was working on a very tricky issue on ProxyManager. The problem is simple: instantiating ReflectionClass or ReflectionProperty is slow, and by slow, I mean really slow! The reason for this research is that I'm trying to optimize a "hydrator" to work with larger data-sets by still keeping a low initialization overhead. PHP 5.4 comes with a new API for Closures, which is Closure#bind(). Closure#bind() basically allows you to get an instance of a closure with the scope of a given object or class. Neat! That's basically like adding APIs to existing objects! Let's break some OOP encapsulation to fit our needs.

He shows how to use this "bind" feature to reach into an object, in this case a "Kitchen", and extract the value of an internal, private property. He also talks some about the performance of this method versus the more typical use of Reflection. He includes two other quick examples too - accessing the same private properties by reference and an abstracted "property reader" closure that uses the bind trick on any object.

0 comments voice your opinion now!
private method reflection closure bind alternative performance

Link: http://ocramius.github.io/blog/accessing-private-php-class-members-without-reflection

PHPMaster.com:
Lesser-Known "Features" of PHP's OO Model
July 22, 2013 @ 12:21:22

On PHPMaster.com there's a new tutorial from Lorna Mitchell about some of the lesser known OOP features that are built in to the PHP language. She talks about things like interface inheritance, private properties and autoloading and type hints.

The vast majority of today's applications written in PHP are object-oriented, and in general the core OOP concepts are pretty well understood by PHP developers. This article pushes the boundary of your understanding and shows you some tricks, or potential pitfalls depending on your perspective, of OOP in PHP.

Besides the ones mentioned above, she also looks at abstract classes and their use as well as the use of "finally" to handle the cleanup after exceptions.

0 comments voice your opinion now!
features oop model language private inheritance typehint finally

Link: http://phpmaster.com/lesser-known-features-of-phps-oo-model

Andrew Podner:
Using Stackato for PHP Applications in a Private PaaS
March 18, 2013 @ 12:17:51

In this new post to his site Andrew Podner looks at using the Stackato software from ActiveState to provide a Platform-as-a-Service environment on any cloud infrastructure.

So, now it is settled, I want to stay inside the corporate firewall, but I want each application isolated from the next, and by the way, there is no budget for any of this. I posted about three PaaS providers a while back, and started thinking that what I really needed was PaaS, but I needed to be able to host the PaaS environment inside a corporate LAN. Off to search the web. Surprisingly, there were not just a ton of viable results in that search. Even more surprising...hard to find one with a "download here" button. No matter how I searched though, one company & product kept popping up: Stackato by ActiveState. The words "Free Micro Cloud" were a very encouraging sign. So let's take this thing for a spin and see just how easy it is...

He walks you through the installation process - downloading the VMs, setting up the initial configuration and how to use the command line tool to deploy your own applications (several come preconfigured though). He also includes an example configuration (YAML) you can use to configure custom applications and some sample code showing a database connection.

0 comments voice your opinion now!
activestate stackato paas private internal review tutorial


Community News:
Privates - Harmful or Useful? (Discussion)
December 12, 2012 @ 09:53:57

There's been a few articles posted on various blogs in the PHP community recently about the "most correct" usage of the "private" scope in your PHP applications. As with any feature of just about any language out there, there's people on both sides of the fence. Here's the ones that have weighed in so far:

  • Brandon Savage's initial post (an excerpt from his upcoming "Do This, Not That" book)
  • A response to this from Anthony Ferrara
  • Brandon's own response to comments on his previous article
  • This new post from Larry Garfield and some of his experience from the Drupal world

Various topics come up during these posts including static coupling, using interfaces versus inheritance, wrapper classes and developer intent.

0 comments voice your opinion now!
private scope visibility harmful blog


Brandon Savage:
Private Methods Considered Harmful ("Do This, Not That" Excerpt)
December 10, 2012 @ 11:26:42

A while back Brandon Savage mentioned a book he was writing ("Do This, Not That") to help PHP developers learn some of the best practices associated with the language. Today he's posted an excerpt from the book for your enjoyment.

This great series of highly focused e-books will offer tips, tricks and best practices focused on core areas of PHP development, including databases, security, filtering, regular expressions, configuration and more. Since it will be a series of tightly targeted solutions, developers will be able to pick all, some or just one of the offerings that solves their specific problem(s).

This excerpt looks at private method use in your applications and why they could be considered "evil" if not used correctly.

0 comments voice your opinion now!
book excerpt private method dothisnotthat introduction bestpractices


Sebastian Göttschkes' Blog:
Extending the Testclass for Unittests
May 02, 2012 @ 11:38:16

In his previous post Sebastian Göttschkes introduced a set of classes you could use for different types of testing in your Symfony2 applications. In his most recent post he expands on these examples, giving the UnitTestClass an extra ability.

In one of my last articles on Testclasses for symfony2 I explained some of the classes I use for my tests. Since then I found a great article on metatesting and want to update my UnitTest class to show some practical examples.

His update allows the class to access private properties via a "getAttribute" method that, via PHP's Reflection, allows you to pull out the private property's value and a "setAttribute" that lets you inject a value back in. He includes a word of warning, though - if you're using something like this often., you're probably "doing it wrong" and might need to think through your application design a bit more.

You can find the source for his classes in his previous post.

0 comments voice your opinion now!
unittest private method class symfony2



Community Events











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


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

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