将可变长度参数列表传递给父级 [英] Passing Variable Length Argument List to Parent

查看:43
本文介绍了将可变长度参数列表传递给父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



你好!


我有一个类方法,它采用可变数量的参数和

正确处理它们使用func_get_args等...


ie


class ABC

{

公共功能MooSaysTheCow()

{

foreach(func_get_args()as $ arg_name => $ arg_value)

{

...

}

}

}


现在,问题是:我想覆盖这个类和这个方法,有

,重写方法调用基类,然后做其他事情。

问题是我不知道如何传递参数。


class DEF

{

公共功能MooSaysTheCow()

{

父母:: MooSaysTheCow(我在这里放什么?????);

echo带有令人兴奋的新功能的被覆盖版本!;

}

}

有什么想法吗?


迄今为止我想到的最好的是非常令人讨厌的,并且不灵活

任意数量的参数.... blech。

class DEF

{

公共函数MooSaysTheCow()

{

switch(func_get_num_args( ))

{

案例1:

父:: MooSaysTheCow(func_get_arg(0));

休息;

案例2:

父:: MooSaysTheCow(func_get_arg(0),func_get_arg(1));

休息;

等....

...

..

解决方案

arg_name =>


arg_value)

{

...

}

}

现在,
问题是:我想覆盖这个类和这个方法,有

,覆盖方法调用基类,然后做其他事情。

问题是我不知道如何传递参数。


class DEF

{

公共功能MooSaysTheCow()

{

父母:: MooSaysTheCow(我在这里放什么?????);

echo带有令人兴奋的新功能的被覆盖版本!;

}

}

有什么想法吗?


迄今为止我想到的最好的是非常令人讨厌的,并且不灵活

任意数量的参数.... blech。

class DEF

{

公共函数MooSaysTheCow()

{

switch(func_get_num_args( ))

{

案例1:

父:: MooSaysTheCow(func_get_arg(0));

休息;

案例2:

父:: MooSaysTheCow(func_get_arg(0),func_get_arg(1));

休息;

等....

...

..


Mark写道:

你好!
我有一个类方法,它采用可变数量的参数,并用func_get_args等正确处理它们......



类ABC
{公共功能MooSaysTheCow()
{foreach(func_get_args()as



hello!

I have a class method that takes a variable number of parameters and
correctly deals with them with func_get_args, etc ...

i.e.

class ABC
{
public function MooSaysTheCow()
{
foreach (func_get_args() as $arg_name => $arg_value)
{
...
}
}
}

now, the problem is: i want to override this class and this method, have
that overriding method call the base class and then do something else. The
problem is that I don''t know how to pass the parameters along.

class DEF
{
public function MooSaysTheCow()
{
parent::MooSaysTheCow( WHAT DO I PUT HERE ????? );
echo "Overridden version with new exciting features!";
}
}
Any ideas?

the best i''ve thought of so far is terribly yucky, and not flexible to
arbitrary numbers of parameters .... blech.

class DEF
{
public function MooSaysTheCow()
{
switch (func_get_num_args())
{
case 1:
parent::MooSaysTheCow(func_get_arg(0));
break;
case 2:
parent::MooSaysTheCow(func_get_arg(0), func_get_arg(1));
break;
etc ....
...
..

解决方案

arg_name =>


arg_value)
{
...
}
}
}

now, the problem is: i want to override this class and this method, have
that overriding method call the base class and then do something else. The
problem is that I don''t know how to pass the parameters along.

class DEF
{
public function MooSaysTheCow()
{
parent::MooSaysTheCow( WHAT DO I PUT HERE ????? );
echo "Overridden version with new exciting features!";
}
}
Any ideas?

the best i''ve thought of so far is terribly yucky, and not flexible to
arbitrary numbers of parameters .... blech.

class DEF
{
public function MooSaysTheCow()
{
switch (func_get_num_args())
{
case 1:
parent::MooSaysTheCow(func_get_arg(0));
break;
case 2:
parent::MooSaysTheCow(func_get_arg(0), func_get_arg(1));
break;
etc ....
...
..


Mark wrote:

hello!

I have a class method that takes a variable number of parameters and
correctly deals with them with func_get_args, etc ...

i.e.

class ABC
{
public function MooSaysTheCow()
{
foreach (func_get_args() as


这篇关于将可变长度参数列表传递给父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆