Re: [vox-tech] PHP: My object's method vanishes

2005-12-09 Thread Peter Jay Salzman
On Fri 09 Dec 05,  3:15 PM, Richard S. Crawford <[EMAIL PROTECTED]> said:
> This is for a wishlist program that I've been developing for my family.
> 
> I have a class called Person which looks something like this:
> 
> 
> 
> class Person {
> 
>   var $personFullName;
>   var $recipientList;
> 
>   function Person ($personKey) {
> global $CFG;
> $personQuery = "select * from ".$CFG->db['prefix']."person where
> personKey = $personKey";
> if (!$person = dbquery($personQuery)) {
>   return false;
> }
> $this = $person[0];
> $this->personFullName = $this->personFirstName . " " .
> $this->personLastName;
> 
>   }
> 
>   function bob() {
>   }
> 
> }
> 
> 
> 
> I can call the constructor object just fine with:
> 
> 
> 
> $USER = new Person($userKey);
> 
> 
> 
> However, when I try this:
> 
> 
> 
> USER->bob()
> 
> 
> 
> I get this error:
> 
> 
> 
> Fatal error: Call to undefined function: bob()
> 
> 
> 
> ...which I don't understand at all, since I have another Class which is
> called in pretty much the same way, and I have no problem calling any
> methods for that other class.  I can't find any significant structural
> differences between the two classes.
> 
> I tried introducing a deliberate error into the definition for the
> function bob(), and sure enough the program died when the page with the
> malformed function was loaded.
> 
> I'm sure I'm missing something very obvious which will embarrass me
> completely once it's pointed out to me, but at the moment I have no idea
> what it might be.
 
Hi Richard,

I assume you meant $USER->bob() and not USER->bob()?

Can you call $this->bob() from within the class?

Are you using editor syntax highlighting that shows open and close braces?
Use of Vim's "%" command saved me numerous times.

Do you have error reporting set to E_ALL?  If not, it's recommended.

I'd be willing to take a look at your code if you want to email a tarball to
me.


Pete
___
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech


[vox-tech] PHP: My object's method vanishes

2005-12-09 Thread Richard S. Crawford
This is for a wishlist program that I've been developing for my family.

I have a class called Person which looks something like this:



class Person {

  var $personFullName;
  var $recipientList;

  function Person ($personKey) {
global $CFG;
$personQuery = "select * from ".$CFG->db['prefix']."person where
personKey = $personKey";
if (!$person = dbquery($personQuery)) {
  return false;
}
$this = $person[0];
$this->personFullName = $this->personFirstName . " " .
$this->personLastName;

  }

  function bob() {
  }

}



I can call the constructor object just fine with:



$USER = new Person($userKey);



However, when I try this:



USER->bob()



I get this error:



Fatal error: Call to undefined function: bob()



...which I don't understand at all, since I have another Class which is
called in pretty much the same way, and I have no problem calling any
methods for that other class.  I can't find any significant structural
differences between the two classes.

I tried introducing a deliberate error into the definition for the
function bob(), and sure enough the program died when the page with the
malformed function was loaded.

I'm sure I'm missing something very obvious which will embarrass me
completely once it's pointed out to me, but at the moment I have no idea
what it might be.

-- 
Richard S. Crawford
http://www.mossroot.com
"That which does not kill me makes me stranger."
--Llewellyn
___
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech