Jump to content
Dany Marmur

Injecting Pascal into PHP?

Recommended Posts

Hello all!

 

This might be the wrong forum. Apologies. It's not about Delphi output.

 

I know some people here uses PHP. I have also read about some integration project.

DWScript transpiles Pascal to JavaScript. Otherwise that would probably be a good candidate...

 

I have just finished a limited job for some commercial entity (not what i usually do). And every now and then when these jobs show themselves i have to fight Word-press or Drupal. 

As a side-note it's interesting to see how little coding competence the consultants managing these sites have. It's not the first time that a php-hater like me have to do the job for them, and the result is not 100% since i refuse to "learn" the idioms of those monsters.

 

So this last time, googling the PHP manual, word-press codex and all i was thinking; a "plugin" that translates ObjectPascal to php! Not that i would have to google the manuals very much less, though.

 

Something like:

 

functions.php:

 

<?php

/**
 * Word-press blah blah...

...

?><?pas
function SeriousCoding(var aTypedVar: string): Boolean;
begin
  return StrToIntDef($_POST["something"], 0);
end;
?><?php

....

?>

or some such.

 

Do you think it would be possible. Is there a OP to PHP transpiler project to start from?

 

TIA,

 

/Dany

Share this post


Link to post

I think this would definitely be possible and I would personally love this since I use WordPress almost every day. Having such a plugin would be pretty cool.

 

It would however be a difficult plugin to write.

Share this post


Link to post
2 hours ago, Markus Kinzler said:

Why converting to PHP and not to HTML/JS directly?

This is for the jobs that require word-press or drupal. The js is not executed on the server. PHP is.

Going node.js as a base for js that in turn is pluggable into server-side code seems a bit convoluted.

But perhaps it is a viable way to go. I do not know enough of PHP it's environment, wp/drupal and their respective "environment".

Share this post


Link to post
15 hours ago, David Heffernan said:

Ugh. Good luck reasoning about the security of such a thing. 

If i could inject a "pas" file into any Drupal php-file then i would work with Pascal that transpiles to PHP and the environment would be exactly the same.

The server would actually execute php and not pascal. I cannot see why transpiled pascal would introduce attack vectors that hand-coded php do not.

But i would appreciate some enlightenment.

 

Maybe you meant Pas => HTML/JS => Node.js + Drupal server side? THAT would open up attack vectors. Yes.

Share this post


Link to post
Posted (edited)

If you're feeling ambitious, you could write an ObjectPascal interpreter that runs on Apache and acts similar to php.

 

The challenge with that is there are elements in Delphi that have syntax and semantics that only apply to compiled code. An interpreted version of Delphi would need to be a little different.

 

TMS Software has an interpreter that supports both BASIC and ObjectPascal syntax that you could probably use as a base for something.

 

There's also DWScript, as was mentioned earlier.

 

The problem with apps like WP and Drupal is they have not been written (historically speaking) in a very object-oriented manner, due to a bias lots of php coders have against OOP, believing it slows down execution time. Last I checked, Python was much slower than php (and fully OOP), yet it's use is growing extremely fast, so I guess execution speed is more of a religious issue than anything else.

 

Then you've got all of the weird ways people do things OOP-wise with php code that would make most serious Delphi, C++, and C# coders gag.

Edited by David Schwartz
  • Like 1

Share this post


Link to post
Posted (edited)

There was an old (very interesting) product from Embarcadero around: HTLM5Builder.

http://www.drdobbs.com/web-development/embarcadero-html5-builder-actually-quite/240006712

Unfortunately this is quite dead and unsupported, but its still there.
The efficieny was not good enough, at that time, so the PHP crowd preferred the traditional PHP Ide's for a good reason.

I would also hope that in one (long distant) future, maybe PHP will be integrated in the IDE as platform too :classic_rolleyes:

Ok, ok, lets stop dreaming :classic_blush:

 

Maybe this is what you're looking for ?

Edited by Rollo62

Share this post


Link to post

PHP has commands to execute a native console program. Including:

 

exec() - Execute an external program
system() - Execute an external program and display the output
passthru() - Execute an external program and display raw output
escapeshellcmd() - Escape shell metacharacters
pcntl_exec() - Executes specified program in current process space

 

Make a console application that does what you want, or outputs HTML. In Delphi you can now make it for Windows or Linux.
You can then use it anywhere on a PHP page:

 

<?php
echo exec("myconsoleprog.exe myparameters");
?>

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×