3

Background

I'm using a 4D server. 4D has a built in PHP processor, but in an odd way. I have to start an inline 4D script in my webpage, then I have to call up PHP Execute, and give it the path of a .php file.

4D Script

C_TEXT($result)
C_BOOLEAN($isOK)
$isOK:=PHP Execute("C:\\php\\myPHPFile.php";"my_function";$result)
ALERT($Result)

myPHPFile.php

<?php
    function my_function() {
        return 'Hello World';
    }
?>

Goal

I want to be able to write this in my webiste:

<?php echo 'Hello World'; ?>

And have it processed. I almost have it figured out. If I first convert it via the server code (4D can do that) to this:

C_TEXT($result)
C_BOOLEAN($isOK)
$isOK:=PHP Execute("";"echo 'Hello World'";$result)
ALERT($Result) 

You are supposed to be able to run PHP native functions directly without a .php file. You'd think that would work. Turns out it doesn't.

So I tried this:

C_TEXT($result)
C_BOOLEAN($isOK)
$isOK:=PHP Execute("";"echo";$result;"Hello World") // I can send parameters
ALERT($Result) 

Still doesn't work. Turns out that I need to evaluate the code using a function.

C_TEXT($result)
C_BOOLEAN($isOK)
$isOK:=PHP Execute("";"eval";$result;"return 'Hello World;'") // I can send parameters
ALERT($Result) 

That SHOULD send "return 'Hello World';" to eval(). Well that STILL doesn't work, because I've found out that eval() isn't actually a function. So what I need to know, after all that background, is this:

Question

Is there a native function in PHP that would work like this:

$evaulatedCode = eval($unEvaluatedCode);
10
  • Just, out of curiosity, where is $Result declared/initialized? Commented Sep 24, 2015 at 20:59
  • C_TEXT($result) is the declaration. Commented Sep 24, 2015 at 21:00
  • Yes, that is why I need a function that would work like eval, so that I can put it in there. Commented Sep 24, 2015 at 21:03
  • To answer the question part eval("\$evaulatedCode = $unEvaluatedCode"); Commented Sep 24, 2015 at 21:06
  • Never heard about that. If you ask me, one of the things you don't need for web development is that proprietary 4D stuff. Commented Sep 24, 2015 at 21:06

1 Answer 1

2

You were pretty close, you have the semicolon in the wrong place in your return statement. Try this:

$isOK:=PHP Execute("";"eval";$result;"return 'Hello World';") 
Sign up to request clarification or add additional context in comments.

4 Comments

Doesn't work. eval was my first thought too, as I explained in the question. But eval isn't a function. It doesn't return a value. I think as I review this more that it isn't possible to do what I want.
Actually, now that I recheck the documentation, I think your return statement should have worked. The manual says: eval() returns NULL unless return is called in the evaluated code, in which case the value passed to return is returned.
That's odd then that it doesn't work. I'm wondering if 4D just isn't treating the eval statement as an official "function".
I suppose anything is possible if it has its own PHP interpreter instead of using the real thing. Did you fix the semicolon as I showed? You had it inside the single quotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.