Jump to content

function overloading


Liquid Fire

Recommended Posts

Everything is possible in its own work around. Here is an example of overloading a function in PHP

 

<?php

class a {

function a() {
	// constructor
	$this->b = new b();
}


function overLoad() {
	// extra data here

	return $this->b->overLoad() "!!!";
}

}

class b {

function b() {
	// constructor
}


function overLoad() {
	// extra data here

	return "The cat is fat";
}

}
?>

 

 

Another alternative might be this (I have not tested this)

 

<?php

class a extends b {

function a() {
	// constructor
}


function overLoad() {
	// extra data here

	return b::overLoad() . "!!!";
}

}

class b {

function b() {
	// constructor
}


function overLoad() {
	// extra data here

	return "The cat is fat";
}

}
?>

 

 

Now as for processing time for the first one, it should not be too bad for 1 class etc. But if you have 5 classes you are trying to do that to, your processing time increases dramatically. I am not sure what the second one result is.

 

Either way if you test it out let us know what you find.

 

--FrosT

Link to comment
https://forums.phpfreaks.com/topic/42019-function-overloading/#findComment-203780
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.