English 中文(简体)
PHP - Faked 多重遗产——如何通过多种参数履行职务
原标题:PHP - Faked Multiple inheritance - How to pass multiple parameters to functions

我发现这一点,同时寻求如何在购买力平价中放弃多重遗产(因为购买力平价并不直接支持多重遗产)。

Can 我在PHP中推广使用1个以上的班级?

此处为:

class B {
    public function method_from_b($s) {
        echo $s;
    }
}

class C {
    public function method_from_c($s) {
        echo $s;
    }
}

class A extends B
{
  private $c;

  public function __construct()
  {
    $this->c = new C;
  }

  // fake "extends C" using magic function
  public function __call($method, $args)
  {
    $this->c->$method($args[0]);
  }
}


$a = new A;
$a->method_from_b("abc");
$a->method_from_c("def");

The problem
The example given here considers only one parameter for the function C::method_from_c($s). It works fine with one parameter but I have several functions of class C, some having 2, some having 3 parameters like this:-

class C {
    public function method_from_c($one,$two) {
        return $someValue;
    }

    public function another_method_from_c($one,$two, $three) {
        return $someValue;
    }
}

而I do not想要改变C类职能定义中的任何内容(必须接受这些许多参数)。 E.g. 我不想在我的<代码>C: 方法_ from_c($,2美元)上使用func_get_args()

public function method_from_c() 
{

     $args = func_get_args();

     //extract params from $args and then treat each parameter
}

可在<代码>>------->--------------------------------------- 我谨打电话<代码>。 C类功能,如<代码>$obj->method_ from_c ($one,$2);

Thanks
Sandeepan

最佳回答
问题回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签