 | News Feed |
Sections
|
| feed this: |  |
Cormac's Blog: Lazy loading of object variables in php using __get()
by Chris Cornutt August 08, 2008 @ 14:22:51
Recently, Cormac posted this look at a method for lazy loading on variables in an object with the magic __get method.
I used the magic method __get() to load the images into the [Product] object when they were needed. __get() is called whenever something tries to access a variable that is not set or publically accessible, so basically I used that to load the images whenever some other piece of code tried to access Product::images.
He includes a quick bit of code that fires off an internal private method for the class that loads up the images. In his example, if they're already loaded, it never gets called.
voice your opinion now!
lazy loading get method image product
Arnold Daniels' Blog: An alternative way of EAV modeling
by Chris Cornutt July 31, 2008 @ 12:54:23
Arnold Daniels has posted some thoughts on a topics recently featured in a cover story by php|architect - EAV modeling.
I had seen this db structure in other project, but didn't know that it was called EAV. For those who don't read php|architect, EAV describes a method of saving a large set of attributes, only some of which apply to an individual entity. Normally you would create a table, with a row for each entity and save each attribute in a column. With EAV you save each attribute as a row.
He suggests two ways to do the modeling - the more "common" way and an alternative way that splits up the data types to make querying simpler (into scalars and arrays). A sample database structure and example query for it are included.
voice your opinion now!
eav modeling database attribute query common alternative method
Andreas Gohr's Blog: Working with Password Hashes in PHP
by Chris Cornutt July 29, 2008 @ 12:57:43
Andreas Gohr has a general overview of hashing in a new post to his blog:
Every good programmer knows, that passwords should never be stored in clear text. Instead a one way hash (or digest) should be used. This way user passwords are not at risk in case of an intrusion.
He points out the multiple ways that PHP offers for both simple hashing (like md5 or sha1) and the true encryption types (like ssha, apr1 and crypt). He shows how they work in the DokuWiki application via a call to auth_cryptPassword to make it and db_get_hash/auth_verifyPassword to check against it.
voice your opinion now!
password hash encrypt method dokuwiki
Debuggable Blog: Programming Psychology II Private methods
by Chris Cornutt July 08, 2008 @ 08:44:58
According to Felix Geisendorfer's newest post on the Debuggable blog, he thinks that "private and protected methods and properties are one of the most stupid concepts of OOP."
This is a thought I first shared at CakeFest Orlando this year, but could not explain properly at the time.
He illustrates with an example of a protected "balance" variable in a BankAccount class. Sure, it's marked as private but less skilled programmers might not use it that way. He recommends a method without the getters/setters to help make the usage of the variable a bit simpler. He also suggests that using protected/private scoping helps to promote "crappy code" - using them to provide a sort of protection for code that you either don't want getting used or hiding it away so the API can't get at it.
voice your opinion now!
private method protected bad code concept stupid getter setter
DevShed: More on Private Methods with PHP 5 Member Visibility
by Chris Cornutt June 25, 2008 @ 13:58:20
DevShed finishes off their series looking a private, public and protected variables and methods in classes with this final look a private methods in PHP5 object-oriented programming.
It's time to leap forward and tackle this final article of the series, which will be focused on covering some additional aspects concerning the use of this kind of class method. In addition, I'll teach you how to utilize the "final" keyword, which is included with PHP 5, to prevent the methods of a specific class from being overridden by any subclass.
They work from a hands-on example to show how they can work with private methods (expanding a bit from last time) and how to use the "final" keyword to restrict any and all modification for a method.
voice your opinion now!
php5 tutorial oop member visibility method property final private
Debuggable Blog: How To Execute Only Specific Test Methods in CakePHP Unit Tests
by Chris Cornutt June 19, 2008 @ 12:52:45
On the Debuggable blog today, Tim Koschutki shows how you can run just the tests you want on your CakePHP application without having to worry about sorting their results out manually.
Most of us familiar with unit testing with CakePHP and SimpleTest know that SimpleTest always executes all methods starting with the string "test". This can be problematic sometimes. At this point you have two options: create a new testcase, put an "x" before every other test name or use the following tip.
His tip puts another layer on top of the usual testing and uses the getTests method to define with of the tests need to be run. If it's defined, SimpleTest will only execute those.
voice your opinion now!
simpletest unittest cakephp framework gettests method
DevShed: Utilizing Private Methods with PHP 5 and Member Visibility
by Chris Cornutt June 19, 2008 @ 07:58:51
DevShed has posted the fifth part of their series looking at the visibility keywords on PHP5's object oriented support today. They've already looked at private, public and protected properties in a class, now they look at the use of making methods private to restrict their use/extension.
Of course, when it comes to specifying how visible a certain class property or method will be, you know that PHP 5 permits you to work with three distinct levels of access, called "public," "protected," and "private" respectively. [...] As you may have noticed, however, I've not taught you how to define private methods yet, which is something that can definitely be very useful if you want to restrict the access to your classes from the outside more severely.
The tutorial shows the creation of a class with private properties and then expands it to include a private method. Then they call it from an object, an example of the error PHP kicks back is there too. He also includes the concept of a "getter" to call the private function from a public one.
voice your opinion now!
private object oriented php5 method tutorial getter
|
Community Events
Don't see your event here? Let us know!
|