PHP basically supports two types of parameter passages for functions: pass by value and pass by reference.
Passing by value does not change the value of the variable outside the function after its internal use. Example:
<?php
function add_some_extra($string)
{
$string .= ' e alguma coisa mais.';
}
$str = 'Isto é uma string,';
add_some_extra($str);
echo $str; // imprime 'Isto é uma string,'
?>
However, if the function parameter is passed by reference through character &
placed immediately before the parameter, the value of the variable will be changed both inside and outside the function. Example:
<?php
function add_some_extra(&$string)
{
$string .= ' e alguma coisa mais.';
}
$str = 'Isto é uma string,';
add_some_extra($str);
echo $str; // imprime 'Isto é uma string, e alguma coisa mais.'
?>
Also, if you are going to use object orientation, you could use the attributes of a class to modify the value of the desired variable within one method, and be able to access it in another method. Based on your code it would look like this:
...
class Condutor{
public $cartaoRFID;
public function verificarCondutor(Request $request)
{
//dados do formulário
$this->cartaoRFID = $request->cartaoRFID;
$cancelaTipo = $request->cancela;
$this->indexJson();
}
public function indexJson()
{
return $this->cartaoRFID;
}
}
What you did is right (if both functions belong to the same class), but as
indexJson
is of no use in the example it is difficult to understand what you are trying to do.– Woss
give a
var_dump
in$this->indexJson($cartaoRFID)
and see if you got the result you wanted– JrD
It’s all right, only you do absolutely nothing with the value, if you give a dd() or var_dump() in the return or inside the function, you will be able to test the values.
– Darlei Fernando Zillmer
Your code has conceptual errors, your code has a no return method and in the other you make the same variable receive it even it is not necessary and to use one method in the other is reserved
$this
and the method name. What you want to do? can improve your question by editing– novic