473,805 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing Variable Length Argument List to Parent


hello!

I have a class method that takes a variable number of parameters and
correctly deals with them with func_get_args, etc ...

i.e.

class ABC
{
public function MooSaysTheCow()
{
foreach (func_get_args( ) as $arg_name => $arg_value)
{
...
}
}
}

now, the problem is: i want to override this class and this method, have
that overriding method call the base class and then do something else. The
problem is that I don't know how to pass the parameters along.

class DEF
{
public function MooSaysTheCow()
{
parent::MooSays TheCow( WHAT DO I PUT HERE ????? );
echo "Overridden version with new exciting features!";
}
}
Any ideas?

the best i've thought of so far is terribly yucky, and not flexible to
arbitrary numbers of parameters .... blech.

class DEF
{
public function MooSaysTheCow()
{
switch (func_get_num_a rgs())
{
case 1:
parent::MooSays TheCow(func_get _arg(0));
break;
case 2:
parent::MooSays TheCow(func_get _arg(0), func_get_arg(1) );
break;
etc ....
...
..
Jul 17 '05
11 4138
.oO(Mark)
nope. probably would have in PHP4, but most certainly not in PHP5.
Hmm. The following works here on PHP5 when called statically:

class TBar {
function doSomething() {
print_r(func_ge t_args());
}
}

class TFoo extends TBar {
function doSomething() {
$args = func_get_args() ;
call_user_func_ array(array('pa rent', 'doSomething'), $args);
}
}

TFoo::doSomethi ng(23, 42);

If called on an instance of TFoo my PHP crashes. But if I declare the
above methods 'static' then it works, even if invoked non-statically ...
i'm still stuck with the switch statement in PHP5, unfortunately.


You could also try it with eval(), as already mentioned in another post.

Micha
Jul 17 '05 #11
Michael Fesser wrote:

Hmm. The following works here on PHP5 when called statically:

class TBar {
function doSomething() {
print_r(func_ge t_args());
}
}

class TFoo extends TBar {
function doSomething() {
$args = func_get_args() ;
call_user_func_ array(array('pa rent', 'doSomething'), $args);
}
}

TFoo::doSomethi ng(23, 42);
aaaah. the problem is that i am trying to do this in the constructor. of
the mysqli class.

argh.

such is life :-).

You could also try it with eval(), as already mentioned in another post.
!aaaieee!

might be the only solution.

thanks much!
Micha


--
I am not an ANGRY man. Remove the rage from my email to reply.
Jul 17 '05 #12

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

Similar topics

5
2802
by: Eric A. Forgy | last post by:
Hello, I am just learning Java and am trying to write a method that does something like //=========================================== public Static List find(double array,double val,String relationalOp) { List list = new ArrayList();
1
2429
by: cirillo_curiosone | last post by:
Hi, i'm new to javascript. I started studing it on the web few weeks ago, but still haven't been able to solve one big problem: HOT TO PASS VALUES FROM A SCRIPT VARIABLE TO A CHILD HTML GENERATED BY FUNCTION. Here'e the point: I'm writing a simple website for showing my photographs. It has a central page with many links (as many as galleries are).
5
2001
by: Greg Swindle | last post by:
Hello, I have a question about how prototyping relates to variables and their scope. Given the following code: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var ParentObject = function() { var objectName = "ParentObject";
3
4522
by: Lyn | last post by:
Hi, I have a Search input form which collects from the user a person's name. I am using LIKE with a "%" suffix in the SQL so that the user does not have to type in the full name. When they hit the Search button, a query is run to search the Person table for a match. This produces a recordset (I am using ADO). If the RecordCount is zero, they get a No Match message. If the RecordCount is 1, a DoCmd.OpenForm is performed to open the...
11
4476
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to accomplish. // - - - - - - - - begin code - - - - - - - typedef int sm_t; typedef int bg_t; sm_t sm; bg_t bg;
1
11867
by: | last post by:
Hi, 1st, I did a search and could not find any info on this, the Google results were good, but I'm still have issues...So any help will be great. I have a frame page, which contains 3 frames (Left, Content, and Footer) In the content page, I have a checkbox, which value is a number (i.e. 500). I would like that, when a user clicks on this checkbox, it will send the value to my LEFT frame. My left frame has an array, where I'm going to...
6
5586
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an object collection and stanrd using it it starts to fall apart. Clearly there is something about javascript's usage of passing "By ref" that i am not getting. i have had a look on the web and found some examples, but i cant see why my code does not...
6
6935
by: virgincita schmidtmann | last post by:
Good evening, I would like to pass the size of an array from the commandline. int main(int argc, int *argv) { .... max=*argv; int list; ....
0
2049
by: zman77 | last post by:
EDIT: -- forgot to mention... I am using Visual Studio 2005, on Win XP, on an intel machine Hi. This is my first post, though I've "lurked" for a while because I find these forums very helpful. Ok my problem is the following. I have a class that contains a "MakeByteArray" function. I have many objects of that class. Inside that function, I have a private variable, that is NOT static. It seems that when I put all these objects in...
0
9716
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10359
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10104
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7645
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5541
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3843
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.