scoping problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wmelnick
Forum Newbie
Posts: 1
Joined: Fri May 09, 2008 6:43 pm

scoping problem

Post by wmelnick »

I have a generic mysql handling class which (among other functions) implements

insert
insertAndRetrieve

I also have a class that extends the above class and has a custom version of insert which encrypts credit card numbers.

The problem is that when insertAndRetrieve is called, it starts with a call to $this->insert which calls the generic one instead of the specific one because $this scopes to the generic (parent) class because insertAndretrieve is not overridden in the subclass. What can I put in place of $this that will make the call to the subclass?

Thanks,
Warren
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: scoping problem

Post by flying_circus »

Warren,

have a look at the PHP documentation for class scope.

http://www.php.net/manual/en/language.o ... otayim.php

You should be able to use the "self::" keyword to access the methods of the subclass or "parent::" keyword to access the methods of the parent class.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: scoping problem

Post by RobertGonzalez »

Can you show the parent class code (relevant bits) and the child classes (again relevant bits) and how you are calling the parent method from the child?
Post Reply