Jump to content

[SOLVED] Returning Variables in Classes "Noob Question"


fredlixo

Recommended Posts

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; }
}

?>

 

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).  ;D

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.