Pass Dynamic Values from one function to another function in class

Varun Sridharan

Hi all i have a function in a class which will print all the variable pass for this function

Class Code :

<?php
 class MyPrintClass {
   public function printVaraible() {
     var_dump(func_get_args())
   }
 }

 $printVar = new MyPrintClass;
?>

if i use like below its correctly working and printing all the values pass.

$print->printVaraible('value1','Value2',20);

The output i got for above cmd

array (size=1)
  0 => string 'value1' (length=6)
  1 => string 'value2' (length=6)
  2 => string 'value3' (length=6)

if i use like blow its showing as a single array.. i want the value seperated.. how its possible ?

function getVal(){
  global $printVar;
  $print->printVaraible(func_get_args());
}

I need to pass the value like below

getVal('value1','Value2',20);

and i need the output as

array (size=1)
  0 => string 'value1' (length=6)
  1 => string 'value2' (length=6)
  2 => string 'value3' (length=6)

Currently i get NULL as the output

Updated Question Based On the Answer Given By deceze ** I Also had a small change in my code** Class Code :

<?php
  class MyPrintClass {
    public function printVaraible($tag,$value) {
      echo $tag.' == '.$value;
      var_dump(func_get_args());
    }
  }

  $printVar = new MyPrintClass;
?>

Converted Class To Function By

<?php
function getVal($tag,$value) {
 global $printVar;
 call_user_func_array([$printVar, 'printVariable'], $tag,$value,func_get_args());
}

?>

If i try to use it as below i get error

<?php getVal('first','second','third,'fourth'); ?>

Warning: call_user_func_array() expects exactly 2 parameters, 4 given

deceze
call_user_func_array([$print, 'printVariable'], func_get_args());

This calls the function with separate parameters from an array. I'd question the usefulness of this though, since you'll just end up with an array from func_get_args anyway. Why not pass arrays around in the first place?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Pass parameter from one Powershell function to another

From Dev

I want to pass variables from one function to another function in codeigniter

From Dev

Passing values from one function to another function

From Dev

How to pass values from one class to another class in TestNG framework

From Dev

How to pass values from Ajax to another function

From Dev

How to pass a function from another class as parameter?

From Dev

flask pass variable from one function to another function

From Dev

Reactjs pass variable to function from another class

From Dev

Accessing a function from one to another dart class

From Dev

How to pass function of one class as argument of another function of another class

From Dev

Get value from One function and pass it to another

From Dev

Pass value from one function to another to calculate with it

From Dev

C Code: Pass string from one function to another function

From Dev

Calling member function of one class from another

From Dev

how to call a variable from one class function to another class function

From Dev

Use values from one javascript function into another

From Dev

pass values from a function to another function in controller

From Dev

Call a python function from one class in another

From Dev

How to use itertools to pass the returned values from one function to another?

From Dev

How to pass arguments from one function to another function in bash scripting?

From Dev

Calling function from one class in another class

From Dev

how to pass the parameter from one function to another function but with in the same class in php

From Dev

Pass last_inserted id from one function to another function in the same class in codeigniter

From Dev

Pass a variable (id) from one function to another function

From Dev

How to pass a value from one function to another

From Dev

Pass a list from one function to another in a class in Python

From Dev

Calling a function from one kotlin class in another

From Dev

how to pass parameter from one page function to another page class function in Javascript / Node js

From Dev

Pass values from one class to another flutter

Related Related

  1. 1

    Pass parameter from one Powershell function to another

  2. 2

    I want to pass variables from one function to another function in codeigniter

  3. 3

    Passing values from one function to another function

  4. 4

    How to pass values from one class to another class in TestNG framework

  5. 5

    How to pass values from Ajax to another function

  6. 6

    How to pass a function from another class as parameter?

  7. 7

    flask pass variable from one function to another function

  8. 8

    Reactjs pass variable to function from another class

  9. 9

    Accessing a function from one to another dart class

  10. 10

    How to pass function of one class as argument of another function of another class

  11. 11

    Get value from One function and pass it to another

  12. 12

    Pass value from one function to another to calculate with it

  13. 13

    C Code: Pass string from one function to another function

  14. 14

    Calling member function of one class from another

  15. 15

    how to call a variable from one class function to another class function

  16. 16

    Use values from one javascript function into another

  17. 17

    pass values from a function to another function in controller

  18. 18

    Call a python function from one class in another

  19. 19

    How to use itertools to pass the returned values from one function to another?

  20. 20

    How to pass arguments from one function to another function in bash scripting?

  21. 21

    Calling function from one class in another class

  22. 22

    how to pass the parameter from one function to another function but with in the same class in php

  23. 23

    Pass last_inserted id from one function to another function in the same class in codeigniter

  24. 24

    Pass a variable (id) from one function to another function

  25. 25

    How to pass a value from one function to another

  26. 26

    Pass a list from one function to another in a class in Python

  27. 27

    Calling a function from one kotlin class in another

  28. 28

    how to pass parameter from one page function to another page class function in Javascript / Node js

  29. 29

    Pass values from one class to another flutter

HotTag

Archive