note 117794 added to filter.filters.misc

From: Date: Tue, 11 Aug 2015 10:47:40 +0000
Subject: note 117794 added to filter.filters.misc
Groups: php.notes 
Request: Send a blank email to php-notes+get-203307@lists.php.net to get a copy of this message
The supplied callback function may also be a class method. (since 5.4.0 ?) To use a method you need to set the options param to an array with two values: the first is the object and the second is the method name. <?php /** * @property-read $language */ class GetInputStore { private $allowed_languages = array('en', 'fr', 'de', 'nl' /*, ... */); private $language; public function __construct(){ $this->language = filter_input(INPUT_GET, 'language', FILTER_CALLBACK, array('options' => array($this, 'get_language_code'))); } public function __get($name){ switch($name){ case 'language' : return $this->language; default : throw new Exception("The GetInputStore class doesn't support GET param \"$name\""); } } private function get_language_code($code){ if(in_array($code, $this->allowed_languages)){ return $code; } else { return 'en'; } } } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 81.82.207.237 ---- Manual Page -- http://php.net/manual/en/filter.filters.misc.php Edit -- https://master.php.net/note/edit/117794 Del: integrated -- https://master.php.net/note/delete/117794/integrated Del: useless -- https://master.php.net/note/delete/117794/useless Del: bad code -- https://master.php.net/note/delete/117794/bad+code Del: spam -- https://master.php.net/note/delete/117794/spam Del: non-english -- https://master.php.net/note/delete/117794/non-english Del: in docs -- https://master.php.net/note/delete/117794/in+docs Del: other reasons-- https://master.php.net/note/delete/117794 Reject -- https://master.php.net/note/reject/117794 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#203307) next »