Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP Functions Function Returns and More PHP Variable Functions

Luis Alveiro Martinez Botello
Luis Alveiro Martinez Botello
2,726 Points

I am running my code but does not show me anything?

<?php

function answer(){ return 42; }

function add_up($a, $b);{ return $a + $b; }

$func = 'add_up';

$num = $func(5, 10);

echo $num();

?>

2 Answers

Hi Luis,

There are just a couple errors in your code. The first one is that you have a semicolon right after the ending parenthesis for your add_up function. Remember that you only need a semicolon after commands.

The other error is that you have $num(); as though it were a function but $num is actually just an integer value because the add_up function returns its result into the $num variable. So, all you need is the variable $num with no parenthesis. With these fixed, your code shows up! :)

<?php

function answer(){ return 42; }

//removed ; after the ) 
function add_up($a, $b) { return $a + $b; }

$func = 'add_up';

$num = $func(5, 10);

//removed () from $num
echo $num;

?>

Excellent! Happy Coding! =]