note 84080 added to language.oop5.patterns
| From: | tedmasterweb at gmail dot com | Date: | Thu, 26 Jun 2008 19:21:08 +0000 |
| Subject: | note 84080 added to language.oop5.patterns | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140850@lists.php.net to get a copy of this message | ||
Regarding Example #1:
Be sure to "sanitize" your variables before using them for including files.
Example #1 assumes the variable $type contains sanitized data (and NOT something threatening like
'../../../../../etc/passwd').
One approach might be as follows:
<?php
switch ( $type ) {
case "MySQL":
$type = 'mysql';
break;
case "SQLite":
$type = 'sqlite';
break;
default:
throw new Exception ('Driver not found');
}
if (include_once 'Drivers/' . $type . '.php') {
$classname = 'Driver_' . $type;
return new $classname;
} else {
throw new Exception ('Driver not found');
}
?>
Naturally, the examples are brief and intended to express the issue at hand, not input sanitizing
methods, but someone might find this note helpful.
HTH
----
Server IP: 69.147.83.197
Probable Submitter: 88.27.252.99
----
Manual Page -- http://www.php.net/manual/en/language.oop5.patterns.php
Edit -- https://master.php.net/note/edit/84080
Del: integrated -- https://master.php.net/note/delete/84080/integrated
Del: useless -- https://master.php.net/note/delete/84080/useless
Del: bad code -- https://master.php.net/note/delete/84080/bad+code
Del: spam -- https://master.php.net/note/delete/84080/spam
Del: non-english -- https://master.php.net/note/delete/84080/non-english
Del: in docs -- https://master.php.net/note/delete/84080/in+docs
Del: other reasons-- https://master.php.net/note/delete/84080
Reject -- https://master.php.net/note/reject/84080
Search -- https://master.php.net/manage/user-notes.php