boionfire81 Posted April 20, 2016 Share Posted April 20, 2016 So in most cases this has been my default/go to for defining a switch get action $_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? $_GET['action'] : null; But lately all that line has been doing is rendering an action unusable. As defining thing is my worst area, I think, can anyone help clue me in as to in which cases that line would not work. Quote Link to comment Share on other sites More sharing options...
Zettieee Posted April 20, 2016 Share Posted April 20, 2016 This looks like a headache. This wont work if $_GET['action'] is a number. /E_ALL ctype_alpha ctype_alnum() works for alphanumeric characters :) Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted April 21, 2016 Share Posted April 21, 2016 So in most cases this has been my default/go to for defining a switch get action $_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? $_GET['action'] : null; But lately all that line has been doing is rendering an action unusable. As defining thing is my worst area, I think, can anyone help clue me in as to in which cases that line would not work. if you have used that from my code that is because i don't use numbers when adding a new switch statement with a get variable Quote Link to comment Share on other sites More sharing options...
Jigsaw Posted April 21, 2016 Share Posted April 21, 2016 try this $_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? $_GET['action'] : null; Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted April 21, 2016 Share Posted April 21, 2016 try this $_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? $_GET['action'] : null; that's what he used but he wants to allow numbers this only allows letters Zettieee is the right way or you could do a preg_replace Quote Link to comment Share on other sites More sharing options...
Zettieee Posted April 22, 2016 Share Posted April 22, 2016 preg_replace_callback() for php7 But why define the action like that for a switch? if the action is null it should goto the default switch Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted April 22, 2016 Share Posted April 22, 2016 Because the warning isn't saying its null. The warning is saying that I hasn't been defined yet. This is where PHP gets stupid since $_GET and the like are global variables but it is trying to save you from a real error Quote Link to comment Share on other sites More sharing options...
Zettieee Posted April 23, 2016 Share Posted April 23, 2016 So why not wrap the switch in an isset and forgot the top code? Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted April 23, 2016 Share Posted April 23, 2016 Because isset() only returns a bool so the cases for that could only be case true: and case false: Quote Link to comment 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.