i have the following code:
function some_function($argument)
{
validate_arg();
//more code
}
function validate_arg()
{
//this function validates the argument of some_function()
}
is it possible for validate_args() to automatically read the argument of
some_function() or do i have to note the argument in the brackets in any
case?
thx, micha
-- 16 1910
micha, is it possible for validate_args() to automatically read the argument of some_function() or do i have to note the argument in the brackets in any case?
No however what you can do is something like the following:
function some_function() {
if (!validate_args(func_get_args())) {
return false;
}
//some_function is valid...
}
This will send all of the arguments from some_function over to
validate_args.
Mike
On Thu, 19 May 2005 07:56:25 -0500, Mike Willbanks wrote: if (!validate_args(func_get_args())) {
From the manual: "This function cannot be used directly as a function
parameter."
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Ewoud Dronkert wrote: On Thu, 19 May 2005 07:56:25 -0500, Mike Willbanks wrote:
if (!validate_args(func_get_args())) {
From the manual: "This function cannot be used directly as a function parameter."
Whoops :)
then:
$args = func_get_args();
if (!validate_args($args)) {
Weird, that is not mentioned in my copy of the manual and you can use
func_get_args() as an argument with no problem in PHP 4. Must be
something new.
Yes. You can use debug_backtrace() to get the arguments to the calling
function.
function validate_arg()
$trace = debug_backtrace();
$args = $trace[1]['args'];
}
On 19 May 2005 09:13:51 -0700, Chung Leong wrote: Weird, that is not mentioned in my copy of the manual and you can use func_get_args() as an argument with no problem in PHP 4. Must be something new.
Maybe, I never tried. It's mentioned here: http://php.net/func-get-args
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
A user note explains it, kind of:
"func_get_arg() does not appear to be allowed to be used as a function
argument itself within class constructors in PHP 5.0.2 (wonk-ay!!!):"
Why on earth are they introducing little changes like this?
> A user note explains it, kind of: "func_get_arg() does not appear to be allowed to be used as a function argument itself within class constructors in PHP 5.0.2 (wonk-ay!!!):"
Why on earth are they introducing little changes like this?
I was looking at the manual and it says that it will work as long as it
is the first parameter in the function.
Mike
Chung Leong wrote: Yes. You can use debug_backtrace() to get the arguments to the calling function.
function validate_arg() $trace = debug_backtrace(); $args = $trace[1]['args']; }
But be aware that debug_backtrace() is only available from PHP 4.3.0 and
greater. If you are coding for an old version, or for a wide audience
that may be using an old version, then it may not be safe to use this
function.
--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Seems to be the case too in PHP 4. I guess it makes some sense, as PHP
has already started pushing the arguments onto the stack if
func_get_args() comes after another argument. Interesting how PHP
pushes arguments in from left to right, whereas in C, the they get
pushed from right to left.
micha <ch*********@web.de> wrote in
news:Xn************************@204.153.244.170: i have the following code:
function some_function($argument) { validate_arg(); //more code }
function validate_arg() { //this function validates the argument of some_function() }
is it possible for validate_args() to automatically read the argument of some_function() or do i have to note the argument in the brackets in any case?
thx, micha
debug_backtrace() is a very good way, because it supplies a lot of other
information too to use in my validator.
thx, micha
--
micha wrote: micha <ch*********@web.de> wrote in news:Xn************************@204.153.244.170:
i have the following code:
function some_function($argument) { validate_arg(); //more code }
function validate_arg() { //this function validates the argument of some_function() }
is it possible for validate_args() to automatically read the argument of some_function() or do i have to note the argument in the brackets in any case?
thx, micha
debug_backtrace() is a very good way, because it supplies a lot of other information too to use in my validator.
thx, micha
Micha,
You have to specify the argument in the brackets. (Well, I
suppose it might be possible to avoid doing so, but why go
looking for trouble?)
So, your code should look like:
function some_function($argument)
{
validate_arg($argument);
//more code
}
function validate_arg($argument)
{
//this function validates the argument of some_function()
}
HTH
Jerry
yes, of course i can specify the argument in the brackets. call it
lazyness not to do so.
debug_backtrace() works well.
micha
chotiwallah wrote: yes, of course i can specify the argument in the brackets. call it lazyness not to do so.
debug_backtrace() works well.
However, the name of this function implies that is supposed to be used
for *debugging* purposes. While obviously you can use it for other
means, if you are using debug operations to achieve your script's main
functionality, it probably means you are going about things the wrong
way.
From a progammatic stance, if you want to pass a bunch of unknown
parameters around, either use func_get_args(), or put them into an
array.
The OP wants to validate a set (presumably of an unknown size) of
parameters with one function, which implies they are all of the same
type. In this instance, I would use an array.
--
Oli
Oli Filth wrote: chotiwallah wrote: yes, of course i can specify the argument in the brackets. call it lazyness not to do so.
debug_backtrace() works well. However, the name of this function implies that is supposed to be
used for *debugging* purposes. While obviously you can use it for other means, if you are using debug operations to achieve your script's
main functionality, it probably means you are going about things the wrong way.
debug_backtrace() is a php function, same as func_get_args(). why not
use it if it is there and does the job?
if we'd only use things for what they are presumably intended, we'd
still be sitting on a tree eating only banana. From a progammatic stance, if you want to pass a bunch of unknown parameters around, either use func_get_args(), or put them into an array.
The OP wants to validate a set (presumably of an unknown size) of parameters with one function, which implies they are all of the same type. In this instance, I would use an array.
-- Oli
i still think debug_backtrace is a good way. i'll explain how i use it.
function some_function()
{
$args = process_args();
//more code
}
function_process_args()
{
$trace = debug_backtrace();
//now $trace[1] contains calling function and it's arguments
require_one func_specs.inc.php
//validate args
//die if not valid
return $valid_args;
}
file func_spec.inc.php contains all argument info in one place, like
min and max argument count, types, allowed values, whatever.
sounds neat to me.
chotiwallah wrote:
<snip> i still think debug_backtrace is a good way. i'll explain how i use it.
function some_function() { $args = process_args(); //more code }
function_process_args() { $trace = debug_backtrace(); //now $trace[1] contains calling function and it's arguments require_one func_specs.inc.php //validate args //die if not valid return $valid_args; }
file func_spec.inc.php contains all argument info in one place, like min and max argument count, types, allowed values, whatever.
sounds neat to me.
Hmm?? At least for me it looks weird.
--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alexander Eberts |
last post by:
I'm new to python so appologies to the group if this question is asked
often. I'm wondering if it's possible to query an object instance to find
out what arguments the instance's __init__ function...
|
by: Rodrigo Daunaravicius |
last post by:
Is there an elegant way to directly refer the 2nd dimension of a
multi-dimensional sequence (like the nth character in a list of strings).
An example would be deleting the newline in all the...
|
by: Christopher Benson-Manica |
last post by:
I appreciate all the responses to my earlier post about accessing
named elements. However, I'm still wondering about my actual problem,
which is that I need to initialize some arrays of named...
|
by: WindAndWaves |
last post by:
Hi Gurus
I have a query that contains reference to the following function:
Public Function UserStatus() As Byte
Const ProEro = 1: 'on error GoTo ERR
'---
UserStatus = Nz(DLookup("", "", "!="...
|
by: fb |
last post by:
Hi Everyone. Thanks for the help with the qudratic equation problem...I
didn't think about actually doing the math...whoops. Anyway... I'm
having some trouble getting the following program to...
|
by: James Thiele |
last post by:
I'd like to access the name of a function from inside the function. My
first idea didn't work.
>>> def foo():
.... print func_name
....
>>> foo()
Traceback (most recent call last):
File...
|
by: Steve Blinkhorn |
last post by:
Does anyone know of a way of accessing and modifying variables declared
static within a function from outside that function? Please no
homilies on why it's bad practice: the context is very...
|
by: Cuthbert |
last post by:
After compiling the source code with gcc v.4.1.1, I got a warning
message:
"/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the
'gets' function is dangerous and should not be...
|
by: eggie5 |
last post by:
See the below objects:
function Manager()
{
this.reports=new Reports();
}
function Reports()
{
//How do I access Manager from here?
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |