Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
[PHP][HELP]Not sure what's wrong with this.[HELP][PHP]
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Heaplink" data-source="post: 233508" data-attributes="member: 8966"><p>$reqs is not declared to any object or array. I guess you wan't to switch $get with $reqs. Also since $_GET is already a short name, I don't see the idea in putting it in a variable.</p><p></p><p>Also never use eval, it can be very evil. So when you wan't to assign a function with the var name you can just do something like</p><p></p><p>[PHP]$funcName = "myfunc";</p><p>$this->{$funcName}();[/PHP]</p><p></p><p>Also you don't need to check if the key $k exists. It does if its iterated in the foreach loop anyway so that condition is not doing anything useful.</p><p></p><p>This is what you mostly want:</p><p>[PHP]foreach($_GET as $k => $v) {</p><p> if(is_string($v)) { // Make sure it's a string, since we can't have an array as function.. duh</p><p> $this->{$v}(); // You could pass arguments here too</p><p> }</p><p>}[/PHP]</p></blockquote><p></p>
[QUOTE="Heaplink, post: 233508, member: 8966"] $reqs is not declared to any object or array. I guess you wan't to switch $get with $reqs. Also since $_GET is already a short name, I don't see the idea in putting it in a variable. Also never use eval, it can be very evil. So when you wan't to assign a function with the var name you can just do something like [PHP]$funcName = "myfunc"; $this->{$funcName}();[/PHP] Also you don't need to check if the key $k exists. It does if its iterated in the foreach loop anyway so that condition is not doing anything useful. This is what you mostly want: [PHP]foreach($_GET as $k => $v) { if(is_string($v)) { // Make sure it's a string, since we can't have an array as function.. duh $this->{$v}(); // You could pass arguments here too } }[/PHP] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
[PHP][HELP]Not sure what's wrong with this.[HELP][PHP]
Top