Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
FILE HOSTS PREMIUM ACCOUNT
ALL FILE HOST PREMIUM ACCOUNTS
Zynga Slingo Trainer v5.12
iTunes Gift Card Generator V3.1 2012
Diablo 3 GOLD Coins FREE
Working PS3 Jailbreak 3.65 And 3.66
ExtaBit Premium Accounts and Cookies
Steam Wallet Hack - Money Adder & Hack v3
Empires & Allies Hack Cheat Trainer v5.4.1
Eve Onnline 60 Days Time Card Generator v2
Popular
XBOX POINTS GENERATOR - MICROSOFT POINTS GENERATOR v1.2012
11 may 2012 premium uploading accounts 100% working
Free Microsoft Points
Free Microsoft Points - Microsoft Points Generator - Xbox Live Codes 2012
Car Town Free Blue Points Hack
Free CarTown Blue Points Generator and CarTown Templates
Better way to get content via jQuery $.get()
Free Microsoft Points
Simple Days Purger
Sharecash Downloader Bypass Surveys New 05/2012
Pastable version of
Base class for easy class property handling
<pre class='prettyprint' language='php'><?php class PropertyHandler { const GET_REGEX = "^get([aA-zZ0-9_]+)$"; const SET_REGEX = "^set([aA-zZ0-9_]+)$"; private $props; function __construct() { $props = array(); } public function __call($method, $arguments) { if($this->isGetMethod($method)) { return $this->execGetMethod($method); }elseif($this->isSetMethod($method)) { return $this->execSetMethod($method, $arguments); }else { throw new Exception("Unhandled method $method"); } } private function isGetMethod($method) { return $this->isTypeMethod($method, self::GET_REGEX); } private function isSetMethod($method) { return $this->isTypeMethod($method, self::SET_REGEX); } private function isTypeMethod($method, $regex) { return (preg_match("/$regex/", $method) > 0); } private function execGetMethod($method) { $matches = array(); preg_match("/" . self::GET_REGEX . "/", $method, $matches); if(count($matches) > 0) { return $this->getProp($matches[1]); } } private function execSetMethod($method, $arguments) { if(count($arguments) > 1) { throw new Exception("Set methods are not allowed to take more than one argument"); } $matches = array(); preg_match("/" . self::SET_REGEX . "/", $method, $matches); if(count($matches) > 0) { $this->setProp($matches[1], $arguments[0]); } } public function setProp($propName, $propVal) { if(!$propName) { throw new Exception("Invalid empty property name"); } $this->props[$propName] = $propVal; } public function getProp($propName) { if(isset($this->props[$propName])) { return $this->props[$propName]; } } } /** * Very simple example */ class PropTest extends PropertyHandler { public function __construct() { parent::__construct(); } } $props = new PropTest(); //Notice that neither PropTest nor PropertyHandler actually have setFirstName or getFirstNames //These are setting and retrieving associative the associative array value with key "FirstName" $props->setFirstName('Mark'); echo $props->getFirstName(); ?></pre> <a href="http://www.refactormycode.com/codes/461-base-class-for-easy-class-property-handling" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>