KevinM1 Posted April 7, 2008 Share Posted April 7, 2008 This has something to do with my last thread with sessions. I'm currently trying my hand at a Front Controller/Registry combo. Nothing complex, just an exercise for me to learn the basic concepts. I have a Request object, which is primarily an object wrapper for the $_REQUEST superglobal array. The Request object works fine, with the exception being a notice thrown when error_reporting(E_ALL) is set. That notice is: Notice: Undefined index: action in /home/nights/www/www/MP/controller/Request.php5 on line 27 The relevant code is: <?php class MP_controller_Request{ private $properties; function __construct(){ $this->init(); MP_base_RequestRegistry::getInstance(); MP_base_RequestRegistry::setRequest($this); } function init(){ if($_SERVER['REQUEST_METHOD']){ $this->properties = $_REQUEST; return; } foreach($_SERVER['argv'] as $arg){ //just in case the command line is used if(strpos($arg, '=')){ list($key, $value) = explode('=', $arg); $this->setProperty($key, $value); } } } function getProperty($key){ if(!empty($this->properties)){ return $this->properties[$key]; // <-- line giving the notice } } function setProperty($key, $value){ $this->properties[$key] = $value; } } ?> The notice is only thrown before a request is sent to the Front Controller (i.e., on initial page load). So, my question is this: does $_REQUEST exist even if a request isn't sent? Because the notice makes it seem as though my code is trying to access the $this->properties array despite it logically being empty. Quote Link to comment https://forums.phpfreaks.com/topic/99999-solved-quick-superglobal-array-question/ Share on other sites More sharing options...
rhodesa Posted April 7, 2008 Share Posted April 7, 2008 Yes, $_REQUEST is always set. Use if(isset($this->properties[$key])){ instead Quote Link to comment https://forums.phpfreaks.com/topic/99999-solved-quick-superglobal-array-question/#findComment-511375 Share on other sites More sharing options...
wildteen88 Posted April 7, 2008 Share Posted April 7, 2008 Id' change this: function getProperty($key){ if(!empty($this->properties)){ return $this->properties[$key]; // <-- line giving the notice } } to: function getProperty($key) { if(is_array($this->properties) && isset($this->properties[$key])) { return $this->properties[$key]; } }[/code Do note that the $_REQUEST superglobal contains both $_POST, $_GET and $_COOKIE data. Quote Link to comment https://forums.phpfreaks.com/topic/99999-solved-quick-superglobal-array-question/#findComment-511378 Share on other sites More sharing options...
KevinM1 Posted April 7, 2008 Author Share Posted April 7, 2008 Thanks, guys! Quote Link to comment https://forums.phpfreaks.com/topic/99999-solved-quick-superglobal-array-question/#findComment-511395 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.