Re: Class calling Class returning 'object'

From: Date: Mon, 27 Feb 2006 23:31:31 +0000
Subject: Re: Class calling Class returning 'object'
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-231170@lists.php.net to get a copy of this message
Jason Gerfen wrote:
I am in need of some assistance working with classes. I have a function (X) which calls a class (A), that class calls another class (B) and returns the results. At this point I think I am doing everything correctly within' class A because if I echo the results of Class A calling Class B the data is displayed. However, when I use 'return $data' from function X (ex. $data = $ClassA->function( $var1, $var2 ); ) the word 'object' is being displayed in the browser. Here is the code; any help, tips, pointers is appreciated. // function 'chooser' calls class 'myAuth' and returns $data function chooser( $level, $page, $user, $pass ) { if( $page == "auth" ) { require 'auth.inc.php'; $data = new myAuth; $data = $data->login( $_POST['user'], $_POST['pass'] );
<snip> Please rename your variables! You're creating an object called 'data' then assigning it to text - which gets even more confusing when you use the same idea in your other classes. $authclass = new myAuth; $login_check = $authclass->login(....) Way easier to read and follow - you'll find your bug easily enough by doing this. -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.general (#231170) next »