TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-27-2008, 05:14 AM   #1 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Location: On your Hard Drive, hiding like a Virus
Posts: 824
Thanks: 163
Orc is on a distinguished road
Default 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.
__________________
Wax on, Wax off
Orc is offline  
Reply With Quote
Old 06-27-2008, 06:26 AM   #2 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
delayedinsanity is on a distinguished road
Default

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
delayedinsanity is offline  
Reply With Quote
Old 06-27-2008, 07:05 AM   #3 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Location: On your Hard Drive, hiding like a Virus
Posts: 824
Thanks: 163
Orc is on a distinguished road
Default

Quote:
Originally Posted by delayedinsanity View Post
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()
__________________
Wax on, Wax off
Orc is offline  
Reply With Quote
Old 06-27-2008, 11:21 AM   #4 (permalink)
The Frequenter
Advanced Programmer Top Contributor Good Samaritan 
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 474
Thanks: 26
sketchMedia is on a distinguished road
Default

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.
__________________
sketchMedia is offline  
Reply With Quote
Old 06-27-2008, 11:23 AM   #5 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Location: On your Hard Drive, hiding like a Virus
Posts: 824
Thanks: 163
Orc is on a distinguished road
Default

Quote:
Originally Posted by sketchMedia View Post
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
__________________
Wax on, Wax off
Orc is offline  
Reply With Quote
Old 06-27-2008, 03:58 PM   #6 (permalink)
The Frequenter
Advanced Programmer Top Contributor Good Samaritan 
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 474
Thanks: 26
sketchMedia is on a distinguished road
Default

Why do you need to use the return keyword with eval, just out of curiosity
__________________
sketchMedia is offline  
Reply With Quote
Old 06-27-2008, 08:10 PM   #7 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 359
Thanks: 3
xenon is on a distinguished road
Default

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 have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 06-27-2008, 08:14 PM   #8 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Location: On your Hard Drive, hiding like a Virus
Posts: 824
Thanks: 163
Orc is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
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.
__________________
Wax on, Wax off
Orc is offline  
Reply With Quote
Old 06-30-2008, 03:53 AM   #9 (permalink)
The Acquainted
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 181
Thanks: 34
ETbyrne is on a distinguished road
Default

Why not just do this?

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

echo 
test_func(); 
__________________
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:54 AM.

 
     

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