# [SUGGEST] - passthru

- Thread: https://externals.io/message/48332
- Original archive: https://news-web.php.net/php.internals/48332
- Started by Mathias Grimm on 2010-05-18T22:40:21+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #48332 — Mathias Grimm — 2010-05-18T22:40:21+00:00

URL: https://externals.io/message/48332#48332

i suggest the passthru functionality to pass parameter to other method
without typing all parameters,like call_user_func_array.

foo(passthru()); = call_user_func_array('foo', `func_get_args()`);


// case 1:

function a($a,$b,$c)
{
//...
}

function aa()
{
a(passthru()); // like call_user_func_array('a', `func_get_args()`);
someOthers();
}

aa('foo','bar','baz');



//case 2:

class base
{
protected function insert(BaseType $object,$a,$b,$c)
{
 }
}

class son extends base
{
public function insert(SonType $object) //type hinting differs from base
{
parent::insert(passthru()); // like call_user_func_array(array('parent',
'insert'), `func_get_args()`);
}
}

$son = new son();
$sonType = new SonType();
$son->insert($sonType,'foo','bar','baz');

-- 
Mathias Grimm

Sun Certified Java Programmer 6.0 #SUN604760
Zend Certified Engineer #ZEND006756

http://mathiasgrimm.com.br
http://phpempregos.com.br

---

## #48333 — Stas Malyshev — 2010-05-18T23:13:44+00:00

URL: https://externals.io/message/48332#48333 · In reply to: #48332

Hi!

> i suggest the passthru functionality to pass parameter to other method
> without typing all parameters,like call_user_func_array.
>
> foo(passthru()); = call_user_func_array('foo', `func_get_args()`);

We already have function with this name: http://us.php.net/passthru

-- 
Stanislav Malyshev, Software Architect
SugarCrm: http://www.sugarcrm.com/
(408)454-6900 ext. 227

---

## #48334 — Mathias Grimm — 2010-05-18T23:50:54+00:00

URL: https://externals.io/message/48332#48334 · In reply to: #48333

ok, sorry!
the name isn't important at this moment,can be anyone, can be pervade for
example.

i'm suggesting new feature, the name can be decided later



On Tue, May 18, 2010 at 8:13 PM, Stas Malyshev <smalyshev@sugarcrm.com>wrote:

> We already have function with this name: http://us.php.net/passthru
>
> --
> Stanislav Malyshev, Software Architect
> SugarCrm: http://www.sugarcrm.com/
> (408)454-6900 ext. 227
>
> --
> 
> 
>
>


-- 
Mathias Grimm

Sun Certified Java Programmer 6.0 #SUN604760
Zend Certified Engineer #ZEND006756

http://mathiasgrimm.com.br
http://phpempregos.com.br

---

## #48338 — Mathias Grimm — 2010-05-19T02:44:31+00:00

URL: https://externals.io/message/48332#48338 · In reply to: #48334

php test source:

<?php
echo "TEST 1\n";
function a($a,$b,$c)
{
  echo "$a $b $c\n";
}

function aa()
{
  call_user_func_array('a',func_get_args());// a(pervade();
}

aa(1,2,3);

echo "TEST 2\n";

class BaseType{}
class SonType extends BaseType{}

class base
{
  protected function insert(BaseType $o,$a,$b,$c)
  {
    print_r(func_get_args());
  }
}

class son extends base
{
  public function insert(SonType $o)
  {
    call_user_func_array(array('parent','insert'),func_get_args()); //
parent::insert(pervade());
  }
}

$son = new son();
$son->insert(new SonType(),1,2,3);


php test result:
TEST 1
1 2 3
TEST 2
Array
(
    [0] => SonType Object
        (
        )

    [1] => 1
    [2] => 2
    [3] => 3
)


On Tue, May 18, 2010 at 8:50 PM, Mathias Grimm <mathiasgrimm@gmail.com>wrote:

> ok, sorry!
> the name isn't important at this moment,can be anyone, can be pervade for
> example.
>
> i'm suggesting new feature, the name can be decided later
>
>
>
>
> On Tue, May 18, 2010 at 8:13 PM, Stas Malyshev <smalyshev@sugarcrm.com>wrote:
>
> > […]
>
>
> --
> Mathias Grimm
>
> Sun Certified Java Programmer 6.0 #SUN604760
> Zend Certified Engineer #ZEND006756
>
> http://mathiasgrimm.com.br
> http://phpempregos.com.br
>



-- 
Mathias Grimm

Sun Certified Java Programmer 6.0 #SUN604760
Zend Certified Engineer #ZEND006756

http://mathiasgrimm.com.br
http://phpempregos.com.br

---

## #48346 — Christian Schneider — 2010-05-19T11:43:47+00:00

URL: https://externals.io/message/48332#48346 · In reply to: #48338

Mathias Grimm wrote:
>   call_user_func_array('a',func_get_args());// a(pervade();

Two things:
a) There is a way of doing it and although it is a bit cryptic I find it
appropriate since I don't consider this something which should be done
in regular code.
b) pervade() could not be a normal function but would have to be a
special language construct as far as I can see as the compiler needs to
know to call a() with multiple arguments. Not desirable IMHO.

If you want to have multiple dynamic arguments to pass on like this I'd
suggest you use one associative array as parameter instead.

Like
	function a($p = array()) { ... }
	function aa($p = array()) { a($p); }
	aa(array("foo" => 42, "bar" => 17));
with the additional benefit of having named (and extensible) parameters
as an added bonus.

- Chris

---

## #48348 — Mathias Grimm — 2010-05-19T11:57:18+00:00

URL: https://externals.io/message/48332#48348 · In reply to: #48346

On Wed, May 19, 2010 at 8:43 AM, Christian Schneider
<cschneid@cschneid.com>wrote:

> If you want to have multiple dynamic arguments to pass on like this I'd
> suggest you use one associative array as parameter instead.
>
> Like
>        function a($p = array()) { ... }
>        function aa($p = array()) { a($p); }
>        aa(array("foo" => 42, "bar" => 17));
> with the additional benefit of having named (and extensible) parameters
> as an added bonus.
>
> - Chris
>

array cant be type hinting defined. i will need to do some extra work
checking type in the reciever function.




-- 
Mathias Grimm

Sun Certified Java Programmer 6.0 #SUN604760
Zend Certified Engineer #ZEND006756

http://mathiasgrimm.com.br
http://phpempregos.com.br
