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

Peter Jay Salzman p at dirac.org
Fri Dec 9 15:28:26 PST 2005


On Fri 09 Dec 05,  3:15 PM, Richard S. Crawford <rscrawford at mossroot.com> 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


More information about the vox-tech mailing list