l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
December 2: Social gathering
Next Installfest:
TBD
Latest News:
Nov. 18: Club officer elections
Page last updated:
2005 Dec 10 04:15

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] PHP: My object's method vanishes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



On Fri 09 Dec 05,  3:15 PM, Richard S. Crawford <rscrawford@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
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.