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

Cormac's Blog:
Read-only object variables in php using magic methods
January 23, 2009 @ 12:09:51

This new post on Cormac's blog shows a little trick you can use to make "read-only" object variables with the help of the handy magic methods built in to PHP5.

You can create read-only object variables by using the "private" keyword and the __get() and __set() magic methods. [...] So now classWithReadOnlyVar::readOnlyVar is only settable from inside the class, but you can read it from anywhere.

His example code initially sets up the read-only variable as a property of the example class. The __get magic method is called to correctly fetch the value but the __set intercepts anything trying to change its value. This same sort of thing can be accomplished with the protected/private keywords in PHP5.

1 comment voice your opinion now!
readonly object variable magic method example


Lukas Smith's Blog:
PHP 5.3.0alpha3 is finally out
December 05, 2008 @ 09:31:26

As Lukas Smith mentions, the latest alpha release for the PHP 5.3 series has been released - PHP 5.3alpha2.

Wow, after what feels like ages PHP 5.3.0alpha3 was just released. Originally we hoped to be able to release now intermediate releases every 2-3 weeks, this one took a good 2 months. Somehow this releases did its very best to stall itself. People that needed to work on things together by chance ended up being busy with other things and vacations in just the right order to make things impossible. Most of this was to be attributed to the namespace discussions, which climaxed in the backslash FUD campaign.

He notes that a stable release is probably looking good in Q1 of 2009 (with namespaces being the delaying factor). He also suggests something that could help make things a bit simpler in the future - making the internals@ mailing list read-only for anyone outside of core developers. A good bit of the confusion and bickering came from those outside the dev team and it didn't help the group come to a decision any earlier.

You can find the official release information for the alpha2 on the main PHP.net website.

0 comments voice your opinion now!
php5 alpha2 release namespace internals mailing list readonly


Mikko Koppanen's Blog:
ImagickPixelIterator is not read-only after all...
November 15, 2007 @ 09:38:00

Mikko Koppanen is back with a tip for users of the ImagickPixelIterator functionality of Imagick - it's not read-only after all.

A few days ago I got a help request from a user: "How do you change pixel color during the iteration with ImagickPixelIterator". My initial response was that ImagickPixelIterator is read-only. Well, I have to admit I was wrong. After searching trough ImageMagick docs I stumbled across an example and noticed that PixelIterator (and therefor ImagickPixelIterator) is not read-only after all.

He illustrates with a code example, one showing how to make the object from an image and how to update every second pixel to be black. Source and result images are also included.

0 comments voice your opinion now!
imagickpixeliterator readonly example imagickpixeliterator readonly example



Community Events





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


language unittest release interview install configure developer list series bugfix podcast application library code laravel threedevsandamaybe community introduction wordpress api

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