473,657 Members | 2,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Default parameter

If possible, how do I use a function to create a default parameter
value? The following gives me an "unexpected '(', expecting ')'"
error, which makes sense.

function DisplayInfo($ID , $startdate=date ("Ydm"), $numdays=7) {
...function here...
}
Jul 17 '05 #1
3 2890
.oO(Mike)
If possible, how do I use a function to create a default parameter
value? The following gives me an "unexpected '(', expecting ')'"
error, which makes sense.

function DisplayInfo($ID , $startdate=date ("Ydm"), $numdays=7) {
...function here...
}


Default arguments have to be constant values, no variables or function
calls. You could use something like this:

function DisplayInfo($ID , $startdate = NULL, $numdays = 7) {
if (is_null($start date)) {
$startdate = date('Ydm');
}
...
}

Micha
Jul 17 '05 #2
Mike wrote:
If possible, how do I use a function to create a default parameter
value?

The following gives me an "unexpected '(', expecting ')'"
error, which makes sense.

function DisplayInfo($ID , $startdate=date ("Ydm"), $numdays=7) {
...function here...
}

The default value has to be a constant. It cannot be a variable or a
class member or (as you noticed) a function call.
function DisplayInfo($ID , $startdate=NULL , $numdays=7) {
if (is_null($start date)) $startdate = date('Ydm');
...function here...
}
--
Mail sent to my "From:" address is publicly readable at http://www.dodgeit.com/
== ** ## !! !! ## ** ==
TEXT-ONLY mail to the complete "Reply-To:" address ("My Name" <my@address>) may
bypass the spam filter. I will answer all pertinent mails from a valid address.
Jul 17 '05 #3
Thanks for clearing that up. I ended up using '$startdate="bl urgh"'

if ($startdate="bl urg"){
$startdate=date ("Ymd");
}

Michael Fesser <ne*****@gmx.ne t> wrote in message news:<9d******* *************** **********@4ax. com>...
.oO(Mike)
If possible, how do I use a function to create a default parameter
value? The following gives me an "unexpected '(', expecting ')'"
error, which makes sense.

function DisplayInfo($ID , $startdate=date ("Ydm"), $numdays=7) {
...function here...
}


Default arguments have to be constant values, no variables or function
calls. You could use something like this:

function DisplayInfo($ID , $startdate = NULL, $numdays = 7) {
if (is_null($start date)) {
$startdate = date('Ydm');
}
...
}

Micha

Jul 17 '05 #4

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

Similar topics

26
15555
by: Alex Panayotopoulos | last post by:
Hello all, Maybe I'm being foolish, but I just don't understand why the following code behaves as it does: - = - = - = - class listHolder: def __init__( self, myList= ): self.myList = myList
18
7822
by: Dan Cernat | last post by:
Hi there, A few threads I had a little chat about default values. I am starting this thread because I want to hear more opinions about the default values of function parameters. Some say they see no use of them. Others say thar they are bad. I like them. So, could anyone tell me why they are in the standard? Are they bad? I do not intend to start war. Nor am I a troll.
2
4989
by: Ekim | last post by:
hy, I've got a question according default parameters of functions that are accessed from different files: ---- logging.h ---- void LogTrace(const char* errorLocation, const char* errorInfo = "-"); // define default-param ---- end of logging.h ---
2
23354
by: Vic Y | last post by:
Hi, I am trying to call a user defined function(UDF) from a stored proc, using a default parameter in the called UDF (e.g. @bid_price_type int = 0 ). However the calling stored proc complains that the UDF is expecting a 2nd parameter when I only provide the @test parameter value. Are default parameter values supported in UDF's? I wld really appreciate anybody's help. Thankyou in advance.
2
5829
by: The Plankmeister | last post by:
Hi... I have a query which I'm accessing through PHP as a stored procedure. However, I need to be able not to pass a couple of parameters in certain situations. When I do this, I get an error: Parameter has no default value. But it works fine in Access when I run the query from there and just hit
7
5322
by: A.M | last post by:
Hi, Do we have default method parameter in C#? Something like this void method1(int i = 12) { .... }
8
3035
by: cody | last post by:
Why doesn't C# allow default parameters for methods? An argument against I hear often is that the default parameters would have to be hardbaken into the assembly, but why? The Jit can take care of this, if the code is jitted the "push xyz" instructions of the actual default values can be inserted. To make things simpler and better readable I'd make all default parameters named parameters so that you can decide for yourself why one to...
4
12653
by: indigator | last post by:
I have an ASP.Net web service class, DataLayer.asmx.cs. I have two constructors for the DataLayer class. One is the default parameter-less one and the second one accepts a string argument. When I am trying to consume this web service from another asp.net application, only the default parameter-less constructor shows up. And if i try creating an instance of the second constructor, it gives me a compiler error saying that No overload of...
8
284
by: William Xu | last post by:
Compiling: template <class T = int> T foo(const T& t) {} int main(int argc, char *argv) {} gcc complains:
7
7051
by: jamesclose | last post by:
My problem is this (apologies if this is a little long ... hang in there): I can define a function in VB.NET with optional parameters that wraps a SQL procedure: Sub Test(Optional ByVal Arg1 As Integer = 0, _ Optional ByVal Arg2 As Integer = 0, _ Optional ByVal Arg3 As Integer = 0) ' Call my SQL proc with the same signature
0
8394
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
8732
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...
0
8605
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...
0
7327
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6164
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
4152
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...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.