Created
October 1, 2011 15:27
-
-
Save lloc/1256180 to your computer and use it in GitHub Desktop.
slotObject in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class slotObject { | |
function set ($input) { | |
$slot = array_keys (get_class_vars (get_class ($this))); | |
if (is_array ($input)) { | |
foreach ($input as $key => $value) { | |
if (in_array ($key, $slot)) { | |
$this->$key = $value; | |
} | |
else { | |
die ("AttributeError: '" . get_class ($this) . "' object has no attribute '" . $key . "'"); | |
} | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related post: http://lloc.de/slots-in-php-wie-in-python.html