Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Strange PHP error

Posted on 2007-11-25
9
Medium Priority
?
340 Views
Last Modified: 2009-12-16
               This code:

function possible($from, $to, $field, $color=$db['color']) {
echo($color);
//....
}

                gives this error:

<br />

<b>Parse error</b>:  syntax error, unexpected T_VARIABLE in <b>/var/www/chess/in.php</b> on line <b>113

</b><br />

                  Why?
0
Comment
Question by:Rok-Kralj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1600 total points
ID: 20345488
>function possible($from, $to, $field, $color=$db['color']) {
this is not possible , ie in the function declaration, to specify a default value from another variable.

you could do this:

function possible($from, $to, $field, $color='x') {
  if ($color === 'x') $color = $db['color'];

...
0
 
LVL 24

Assisted Solution

by:glcummins
glcummins earned 396 total points
ID: 20345489
The array $db does not exist within the scope of this function. Try something like this:

function possible($from, $to, $field, $color=null) {

if (!color)
{
   $color=$db['color'];
}

   echo($color);
//....
}
0
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 20345490
$color=$db['color']  is not correct code.

What you want to do is

function possible($from, $to, $field, $color) {....

Then call the function with

possible($from, $to, $field, $db['color']);
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 24

Expert Comment

by:glcummins
ID: 20345491
Sorry, need to add

  global $db;

 to the top of the function.
0
 
LVL 12

Author Comment

by:Rok-Kralj
ID: 20345629
yodercm... Your solution is pointless. Because your script excludes functionality I wanted to acheve at first place.

Apart from his solution, thanks!
0
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 20345666
Gee, I'm sorry you can't use it, even though it works just fine and answers your question as asked.  I don't mind not getting points if it didn't work for you, but your attitude and insulting comments, and deliberately excluding me from even a "thanks" for the attempt to help, make it extremely unlikely I'll ever try to help you again.  
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 20345675
Rok-Kralj,

Your first snippet of code actually did not give me  the idea that you have been working with php for a long time. The comment by yodercm therefor was one all experts could have made, by assuming your level of php expertise based on your own posting.

I agree with yodercm that your attitude is misplaced and does not motivate experts to help you in the future.

-r-
0
 
LVL 12

Author Comment

by:Rok-Kralj
ID: 20345737
Sorry, youdercm, but I was asking about tehnical reason why this is not working... Answer good enough would be:

Giving default value as variable to function is invalid.

I just told why your answer is not suitable... At least it is not the first.

This invention of ex-ex in to use:
Rok-Kralj, Qualified Expert
Guru on this subject.

And about saying thanks at the end... It is not common here. Only one asker did it in my whole career here.

Thanks to all of you!
0
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 20345870
And since my statment :  

>> $color=$db['color']  is not correct code.

is equivalent to your statement :  

>> Giving default value as variable to function is invalid.

I have to disagree that my answer was "not suitable".  

And while it was not the "first", it was posted simultaneously with two others.

However, forget who got points, the thing that disturbs me even still is your attitude with the statement :

>> And about saying thanks at the end... It is not common here. Only one asker did it in my whole career here.

I think you better look around.  It's very rare not to get thanked, even when my answer is not chosen, and rarer still to be insulted for posting a potential answer.  

Experts on EE are volunteers, and aside from the occasional T-shirt, they get no reward except the thanks of those whom they try to help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question