Re: Determining an external function/method's argument/parameter listing..?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ok, thanks for that referral.

The following code shows a bit of a simple usage of the reflectionMethod class, on a quickly generated test class and one of it's methods:

<?php
class myClass
{
public function __init() {

}//end of __init

public function anything($sVar1 = "5") {

}//end of anything function
}//end of myClass

$className = "myClass";
$methodName = "anything";
$r = new ReflectionMethod($className, $methodName);
$params = $r->getParameters();
echo "<ul>\n";
foreach ($params as $param)
{
echo "<li><ul>\n";
echo "<li>parameter: " . $param->getName() . "</li>\n";
echo "<li>allowsNull: " . strval($param->allowsNull()) . "</li>\n";
echo "<li>optional: " . strval($param->isOptional()) . "</li>\n";
if ($param->isOptional()) { echo "<li>defaultValue: " . $param->getDefaultValue() . "</li>\n"; }
echo "</ul></li>";
}
echo "</ul>\n";

?>


Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'

----- Original Message ----- From: "Toby Hart Dyke" <toby@xxxxxxxxxxxx>
To: "'Jacob Kruger'" <jacob@xxxxxxxxxxxxx>
Sent: Tuesday, June 12, 2012 5:35 PM
Subject: RE: Determining an external function/method's argument/parameter listing..?



You need to take a look at reflection in the PHP manual
(http://www.php.net/manual/en/book.reflection.php). From the introduction:

"PHP 5 comes with a complete reflection API that adds the ability to
reverse-engineer classes, interfaces, functions, methods and extensions.
Additionally, the reflection API offers ways to retrieve doc comments for
functions, classes and methods."

Sounds like what you're looking for.

 Toby


-----Original Message-----
From: Jacob Kruger [mailto:jacob@xxxxxxxxxxxxx]
Sent: Tuesday, June 12, 2012 10:38 AM
To: php-windows@xxxxxxxxxxxxx
Subject:  Determining an external function/method's
argument/parameter listing..?

If I managed to determine that a ffunction/method exists for an external
class, by finding it in the array returned by the
get_class_methods('className') function, but, then how would I determine the
required/possible parameters for one of those functions/methods..?

Inside a function itself you can call something like func_get_args() but
that is, I think, meant to return a list of passed arguments/parameters, and
can only be called from inside a function itself, whereas, I would like to
possibly determine what arguments/parameters a function expects/requires,
hopefully then at least being able to derive from the names what
types/values they then expect..?

In other words, would like to find some way to find out the sort of function
definition etc.

And, yes, it would be nice to have a look at the source code am referring
to, but in this specific case, it seems like it might not be best to ask too
many questions...<smile>

Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'




--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux