I have a method that requires two variables to pass through it but for some reason the second one doesn't. I've tried tons of stuff but nothing seems to work.

function get_area_number($area, $company='daniweb'){
	echo '>> '.$company;
}

Thats the method, nothing is displayed for the $company echo unless I declare it just before the echo. This is how I call it

$area_number = $get_area->get_area_number('an area','daniweb');// Doesn't work
$area_number = $get_area->get_area_number('an area');// Doesn't work
$area_number = $get_area->get_area_number('an area',$daniweb);// Doesn't work

I don't know where to go from here so I was hoping someone here would have an idea, any feedback is appreciated.

Member Avatar for langsor

Of course you want to use a return not an echo ... right

<?php
class Get_Area {
  public function get_area_number( $area, $company='daniweb' ){
    echo "$company\n";
    return $company;
  }
}

$get_area = new Get_Area();

$area_number = $get_area->get_area_number('an area','daniweb'); // Works
$area_number = $get_area->get_area_number('an area'); // Works
$daniweb = 'daniweb';
$area_number = $get_area->get_area_number('an area',$daniweb); // Works

echo $area_number;
?>

Well the method does alot more, I'm just using the echo to see if anything is coming through the parenthesis, $company isn't. I do eventually return a variable but its a long script and irrelevant to the problem at hand.

If I have

function get_area_number($area,$company='daniweb'){
	$company = 'daniweb';
	echo '>> '.$company;

it displays
>> daniweb

I'm really lost with this error :confused:

Member Avatar for langsor

The snippet I posted works, based off your original post. Therefore the issue is being produced somewhere in the code you did not show us...

Let's have a look.

Well do I feel like a tit or what.

I was actually working off of a back-up file I have in a different directory and so while the code was the same and the file name was the same the page I was viewing in my browser wasn't being affected.:|

Thanks for your response and sorry for wasting your time :D

Member Avatar for langsor

I don't even want to say how many times I've done that...and after a decade of programming you think I would consider that when the changes I'm making aren't having any effect.

Ciao

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.