TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 06-10-2010, 12:36 AM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default ReflectionClass problem

Heya, as mentioned before on this forum these type of stuff barely got any documentation so I kinda need your help.

I got like this:
PHP Code:
$class = new ReflectionClass('WelcomeController');
$controller $class->newInstance();

$class->getMethod($method)->invokeArgs($controllerRequest::$_arguments); 
Some other code is in between that but that doesn't matter.
As you probably figured out, this is used in a MVC enviroment. The problems are several.

1. If I access in the URL index.php/controller/method/arg1/arg2/ it will successfully access the method in the corresponding controller even if the method does not have any arguments at all. As an example, let's say I have this function inside the controller WelcomeController:
PHP Code:
public function index() { echo 'hello'; } 
If I navigate to index.php/welcome/index/test/test it will output "hello" even though it should output a 404(or at least some kind of error - the 404 support I will probably have to add myself).

2. If I instead have a method with 2 arguments, like this:
PHP Code:
public function index($arg1$arg2) { echo 'hello'; } 
and I navigate to index.php/welcome/test/ with the first argument but not the second argument I get a PHP error:
Code:
Warning: Missing argument 2 for WelcomeController::index() in /Users/Tanax/Desktop/Websites/TanaxiaFramework5/modules/welcome/controllers/welcome.php  on line 6

Notice: Undefined variable: arg2 in /Users/Tanax/Desktop/Websites/TanaxiaFramework5/modules/welcome/controllers/welcome.php on line 9
The warning was alright, at least I got a warning for missing argument(unlike the case in problem #1). The notice however should not even be there since it should not be able to call the method due to wrong amount of arguments(there is not a method called index with 1 argument which was the method I was called in the URL).

The funny thing here is also that it actually outputs part of the method, except for the variable arg2 which is replaced by blank.

So basically, how can I check if a method exists with the amount of arguments that I specify? I know I can check if a method exists via ReflectionClass->hasMethod('name') but that only checks if the method name exists and not any possibilities to add in arguments in the equasion.

Any ideas?
__________________
Tanax is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Huge Session Problem Killswitch General 1 11-17-2008 02:36 AM
Problem with Query + While $a = mysql_fetch_array($b) Aaron Absolute Beginners 0 07-03-2008 07:16 PM
Strange string comparison problem Jelmer General 0 05-23-2008 04:00 PM
A serious curl checkbox problem bedri Advanced PHP Programming 1 05-22-2008 04:25 PM
A bug or a cache problem?! yazid Advanced PHP Programming 0 05-22-2008 08:40 AM


All times are GMT. The time now is 03:53 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design