473,404 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Overwriting functions in PHP?

Is ist possible, to overwrite a function in PHP by calling the parent
function that has the same name?
I have a classA and a classB with a method funcDisplay():

----------------------------------

classA {

function funcDisplay()
{
print "line 1A";
print "line 2A";
}

}

-----------------------------------

classB extends classA
{

functionm funcDisplay
{
$this->funcDisplay();
// should call the func of the parent class!

print "line 1B";
print "line 2B";
}

}
When I test this, I get an memory failure and a fatal error message from
windows. I think $this->funcDisplay is an endless loop by calling
itself. But how can I tell this the PHP compiler to use the upper class?

I want to call from funcDisplay() from classB the funcDisplay() in
classA, that I get the inherited function of the parent class like the
following result:

----
line 1A
line 2A
line 1B
line 1B
----

I thank you in advance,

Lars
Jul 17 '05 #1
3 3045

"Lars Plessmann" <La************@gmx.de> wrote in message
news:c7*************@news.t-online.com...
Is ist possible, to overwrite a function in PHP by calling the parent
function that has the same name?

<snip>

Yes, use parent: http://uk.php.net/manual/en/keyword.parent.php.

The example given is:
<?php
class A {
function example() {
echo "I am A::example() and provide basic functionality.<br
/>\n";
}
}

class B extends A {
function example() {
echo "I am B::example() and provide additional
functionality.<br />\n";
parent::example();
}
}

$b = new B;

// This will call B::example(), which will in turn call A::example().
$b->example();
?>
HTH
Garp
Jul 17 '05 #2
"Lars Plessmann" wrote
$this->funcDisplay();
// should call the func of the parent class!
No, this is called recursion, and like you expected this calls itself, until
it runs out of memory.
But how can I tell this the PHP compiler to use the upper class?


See http://php.net/keyword.parent

Adriaan
Jul 17 '05 #3
Lars Plessmann wrote:
Is ist possible, to overwrite a function in PHP by calling the parent
function that has the same name?
I have a classA and a classB with a method funcDisplay():

----------------------------------

classA {

function funcDisplay()
{
print "line 1A";
print "line 2A";
}

}

-----------------------------------

classB extends classA
{

functionm funcDisplay
{
$this->funcDisplay();
// should call the func of the parent class!

print "line 1B";
print "line 2B";
}

}
When I test this, I get an memory failure and a fatal error message from
windows. I think $this->funcDisplay is an endless loop by calling
itself. But how can I tell this the PHP compiler to use the upper class?

I want to call from funcDisplay() from classB the funcDisplay() in
classA, that I get the inherited function of the parent class like the
following result:

----
line 1A
line 2A
line 1B
line 1B
----

I thank you in advance,

Lars


it works!!
many thanks :-)
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ellixis | last post by:
Hello, How can I use fwrite() and fseek() in order to write data in the middle (or anywhere else) of a file without overwriting existing data ? People told me that I should load the file into...
8
by: Stewart | last post by:
is there any way this can be done? I've looked at the help files and checked out as many tutorials as i could find on the net (as always) but no joy. thanks
1
by: chris kittell | last post by:
Hi All, on db2 v8.1 for linux 32 bit redhat 7.3, when installing fixpak6,it's overwriting the symbolic link that I defined for the install directory, and proceeding to fill up my root partition....
1
by: Chance Lerro | last post by:
Here's another way to PREVENT the install program for run-time Access from overwriting existing file associations: 1. Edit the Runtime MSI file with Orca, InstallShield, etc.. 2. Go to the...
9
by: Robert | last post by:
Hi, Is it me or is the recv() function not erasing but only overwriting the last data it supplied? example: when i first send: "login robert test"
19
by: tweak | last post by:
I have been messing around with buffers, and I found it peculiar that the code below will run without a segmentation fault. As far as I know, overwriting the allocated space from a call to...
1
by: Sargas Atum | last post by:
I have to sort the contents of each column, by default you can sort the column just on clicking on the column head. That works by default. I have to sort another column by the contents of the...
11
by: Steven Jones | last post by:
I have a C program that prints out two lines as follows: Line 1 Line 2 What I would like is for this program to sleep for one second, and then print out two more lines, overwriting the...
5
by: Reckoner | last post by:
I have multiple packages that have many of the same function names. Is it possible to do from package1 import * from package2 import * without overwriting similarly named objects from...
27
by: Jason | last post by:
Hi, I need to open an existing file, seek to a position at X number of bytes, and write out Y number of bytes overwriting any existing bytes, but no erasing any other data. Is this possible? ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.