TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   return keyword (http://www.talkphp.com/general/3016-return-keyword.html)

Orc 06-27-2008 04:14 AM

return keyword
 
Is this the ONLY bloody keyword to not allow data go up at the top

My problem is, I want to kill "return" in the function scope. I hate it, and it's the only thing I know that will allow me to return data without making it go to the top of the canvas of the page.

PHP Code:


function test() {

echo 
"test";



The above function will always output at the top, after all the rest of the data that is outside the variable scope, please help.. Do not say use Return.

delayedinsanity 06-27-2008 05:26 AM

Sorry, I may be the only one, but I'm not following. What are you trying to do?

Most of the methods and functions I use return data (a lot of those simply because all I want is a boolean response from them). I do use a few that directly output data using echo or other means, and they display that data where ever I want them to, based on where I put the function call.

Edit: I gotta ask why do you hate return? The basic idealogy behind a function is that it returns something, a value, be it boolean, data, etc. Look at PHP's built in functionality. substr() doesn't directly echo data, it returns it to you.
-m

Orc 06-27-2008 06:05 AM

Quote:

Originally Posted by delayedinsanity (Post 16082)
Sorry, I may be the only one, but I'm not following. What are you trying to do?

Most of the methods and functions I use return data (a lot of those simply because all I want is a boolean response from them). I do use a few that directly output data using echo or other means, and they display that data where ever I want them to, based on where I put the function call.

Edit: I gotta ask why do you hate return? The basic idealogy behind a function is that it returns something, a value, be it boolean, data, etc. Look at PHP's built in functionality. substr() doesn't directly echo data, it returns it to you.
-m

Cause it hates eval() | assert()

sketchMedia 06-27-2008 10:21 AM

I have no idea what your on about. the only thing i can even remotely imagin you can mean is:
PHP Code:

ob_start();
function 
test() { 
    echo 
"test"
}  
test();

$lol ob_get_clean(); 

A wild stab in the dark, but meh.

Orc 06-27-2008 10:23 AM

Quote:

Originally Posted by sketchMedia (Post 16090)
I have no idea what your on about.

I cannot use the return keyword in eval(), it doesn't work. And Im speaking with inside the function scope, when I use echo it works, or print, sprintf, printf, fprintf. whatever

sketchMedia 06-27-2008 02:58 PM

Why do you need to use the return keyword with eval, just out of curiosity

xenon 06-27-2008 07:10 PM

What are you talking about?

PHP Code:

function test_func()
{
    return 
'return value of the test function';
}

eval(
'$return = test_func();');

echo 
$return

$return will contain exactly the string returned by the function. So, what is the problem? I really don't see why you would want to do such thing anyway...

Orc 06-27-2008 07:14 PM

Quote:

Originally Posted by xenon (Post 16108)
What are you talking about?

PHP Code:

function test_func()
{
    return 
'return value of the test function';
}

eval(
'$return = test_func();');

echo 
$return

$return will contain exactly the string returned by the function. So, what is the problem? I really don't see why you would want to do such thing anyway...

I want the eval() inside the function scope.

ETbyrne 06-30-2008 02:53 AM

Why not just do this?

PHP Code:

function test_func()
{
    eval(
'$var = "val";');
    return 
$var;
}

echo 
test_func(); 



All times are GMT. The time now is 07:59 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0