fredlixo Posted December 15, 2008 Share Posted December 15, 2008 Hello PPL, When requesting for A.php I would like that the code presented below will output the following: stdClass Object ( [A] => 123 <strong> => asdads [C] => 3240vxcv ) However, when returning variable $q used in func_B there is no output. At the moment, that doesn't make any sense to me. What is it that I'm missing here? Can someone provide for proper solution? And what is the explanation for this? I can't figure it out from the php manual examples. Thanks in advance. file A.php <?php require_once 'B.php'; $ops = new ops_class; function test() { global $ops; $arg->A = '123'; $arg->B = 'asdads'; $arg->C = '3240vxcv'; # ... etc $result = '<pre>'; $result .= print_r($ops->func_A($arg)); $result .= '</pre>'; echo $result; } test(); ?> file B.php <?php class ops_class { function func_A($q) { return $q; // se esta linha for comentada, não aparece nada! return func_B($q); } function func_B($q) { return $q; } } ?> Link to comment https://forums.phpfreaks.com/topic/137025-solved-returning-variables-in-classes-noob-question/ Share on other sites More sharing options...
Mad Mick Posted December 15, 2008 Share Posted December 15, 2008 Your return func_B($q); in func_A is redundant since you have already done a return $q before and so ended the function. So effectively both func_A and func_B do the same thing. Link to comment https://forums.phpfreaks.com/topic/137025-solved-returning-variables-in-classes-noob-question/#findComment-715659 Share on other sites More sharing options...
fredlixo Posted December 15, 2008 Author Share Posted December 15, 2008 Thx Mad Mick, My mistake there: the following line: return $q; // se esta linha for comentada, não aparece nada! should be removed. What the coment says is that if this line is removed, the result will not work. About the redundancy of the functions that is out of question. In my original code, the functions involved do more than returning $q. This is meant to be a plain example of what I'm trying to test. PHP will not know anything about redundancy (i think). Link to comment https://forums.phpfreaks.com/topic/137025-solved-returning-variables-in-classes-noob-question/#findComment-715664 Share on other sites More sharing options...
fredlixo Posted December 15, 2008 Author Share Posted December 15, 2008 There is a $this->func_B missing... Sorry! Link to comment https://forums.phpfreaks.com/topic/137025-solved-returning-variables-in-classes-noob-question/#findComment-715667 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.