Archive for July, 2008

Overloading in PHP must use public methods

Friday, July 25th, 2008

The magically overloading methods in PHP, such as __get, and __set must be public according to The PHP Manual.

Aleksis recently pointed that out to me by making his new methods public, which gave me the initiative to look it up at the manual.

I thought this script to convert them might end up being useful to others, too:

for i in `find -iname "*.php"
               |xargs egrep -i "(private|protected) function __(get|set)"
               |awk -F: '{print $1}'`
do 
sed 's/\(private\|protected\) function __\(get\|set\)/public function __\2/' $i >$i.processed;
mv $i.processed $i
done