Pretty new to PHP here, and I was wondering why I can't echo out variables from one section of php to the other when the first instance of the variables appear inside a class.
Here's my example class:
Code: Select all
class myClass {
function myFunction {
$user_info = array(
'username' => $result['auth']['user']['username'],
'fullname' => $result['auth']['user']['fullname'],
);
}
}Code: Select all
<?php
include 'myClass.php';
$class = new myClass();
$class->myFunction();
?>
<html>
<head></head>
<body>
<?php print_r($user_info); ?>
</body>
</html>I guess this boils down to three main questions: Is it possible for me to do this? If so, how? And last, is this method even good practice? Basically, because I am new, I don't know the best method to write clean organized code and I am getting the feeling that this is a bad way to go about it.
Thanks in advance!