ole
November 23, 2021, 3:24pm
1
Hello,
I have a probably simple problem, but do not see the solution.
in the controller I wrote a function in an action and I can’t access the return values, because the variable is supposedly not defined…
function test(){
$test = 1;
return $test;
}
echo $test;
Can anyone help me?
Thanks and best regards
Ole
Zuluru
November 23, 2021, 7:49pm
2
Are you aware that echo $test;
is not actually in your function?
ole
November 24, 2021, 11:36am
3
yes,
my code:
<?php
...
class AllocationsController extends AppController
{
public function a()
{
...
function b(){
--do something e.g.--
$test = 1;
return $test;
}
debug($test);
}
}
output: null
i can not get $test outside of function b().
ole
November 24, 2021, 12:07pm
4
ok, thanks!
the solution is: i have to use references…
atlet
November 24, 2021, 12:10pm
5
<?php
...
class AllocationsController extends AppController
{
function b(){
--do something e.g.--
$test = 1;
return $test;
}
public function a()
{
$test = $this->b();
debug($test);
}
}
You need to put function outside function and call that function in function.
1 Like