Recent

Author Topic: PHP2Pascal anybody?  (Read 1495 times)

domasz

  • Hero Member
  • *****
  • Posts: 553
PHP2Pascal anybody?
« on: February 24, 2024, 10:29:50 am »
So there is this little known language called PHP used mostly for web development.
Perhaps it would be nice to port some of its functions/classes to Free Pascal so PHP programmers could migrate to Pascal and start making GUI apps?
There is a similar project re-implementing PHP functions in JS:
https://github.com/locutusjs/locutus
https://locutus.io/

Their approach, which I really like:
"Our philosophy follows The McDonald’s Theory. This means that we don’t consider it to be a bad thing that many of our functions are first iterations, which may still have their fair share of issues. We hope that these flaws will inspire others to come up with better ideas."

There are already some functions ported to Pascal. For example @Fibonacci ported zlib/deflate/gzip:
https://github.com/fibodevy/zflate
and I did some image functions:
https://forum.lazarus.freepascal.org/index.php/topic,66017.0.html
I am sure more could be find on-line and added to the project.

What do you guys think?

Thaddy

  • Hero Member
  • *****
  • Posts: 16199
  • Censorship about opinions does not belong here.
Re: PHP2Pascal anybody?
« Reply #1 on: February 24, 2024, 11:08:25 am »
i have a license for Delphi for PHP, based on phpfordelphi, but there exists a phpforlazarus for many, many years that is based on the same sourcecode and by the same principal author that licensed his code to Embarcadero. Everything else is basically copying.
Note that that code is very permissively licensed.
« Last Edit: February 24, 2024, 11:21:02 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

domasz

  • Hero Member
  • *****
  • Posts: 553
Re: PHP2Pascal anybody?
« Reply #2 on: February 24, 2024, 11:12:02 am »
PHP4Delphi is something different. It allows you to bundle PHP interpreter with your Delphi program and run PHP code from inside Delphi.

Thaddy

  • Hero Member
  • *****
  • Posts: 16199
  • Censorship about opinions does not belong here.
Re: PHP2Pascal anybody?
« Reply #3 on: February 24, 2024, 11:25:13 am »
No. That product contains a complete rtl and complete vcl in native PHP. It was very promising, but alas abandoned too early around the time I completely gave up beta-testing for Delphi, since it looked pointless. (when, or just before, Barry Kelly left) At that point in time Delphi had to cope with destructive management. Hence Codegear formed, at considerable personal cost for some of the individual engineers, but engineers are not necessary good managers.
« Last Edit: February 24, 2024, 11:33:06 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

domasz

  • Hero Member
  • *****
  • Posts: 553
Re: PHP2Pascal anybody?
« Reply #4 on: February 24, 2024, 11:41:31 am »
No. That product contains a complete rtl and complete vcl in native PHP. It was very promising, but alas abandoned
No wonder it's abandoned if they can't even explain what that is.
Anyway- my idea is the opposite. Not RTL and VCL in PHP but all PHP functions/classes in Pascal.
« Last Edit: February 24, 2024, 11:47:00 am by domasz »

Thaddy

  • Hero Member
  • *****
  • Posts: 16199
  • Censorship about opinions does not belong here.
Re: PHP2Pascal anybody?
« Reply #5 on: February 24, 2024, 11:48:34 am »
that is what that product does!

comparable with pas2js and/or wasi/wasm.
If I smell bad code it usually is bad code and that includes my own code.

domasz

  • Hero Member
  • *****
  • Posts: 553
Re: PHP2Pascal anybody?
« Reply #6 on: February 24, 2024, 12:03:12 pm »
Please forgive me but I still don't understand what PHP4Delphi is.
Can I use it to quickly port/convert/run my existing PHP code in Lazarus/FPC at the speed of compiled code (and not at the speed of slow PHP interpreter)?

Thaddy

  • Hero Member
  • *****
  • Posts: 16199
  • Censorship about opinions does not belong here.
Re: PHP2Pascal anybody?
« Reply #7 on: February 24, 2024, 12:07:30 pm »
no. But that is not the point for server based software.
and ask the author, who happens to be a forum member....
« Last Edit: February 24, 2024, 01:44:47 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Fibonacci

  • Hero Member
  • *****
  • Posts: 614
  • Internal Error Hunter
Re: PHP2Pascal anybody?
« Reply #8 on: February 24, 2024, 05:34:55 pm »
I wouldnt say PHP programmers will move to Pascal if there were similar functions. Imho every "native compiled language" programmer should be familiar with either PHP or JS+some runtime (such as Node.js).

PHP at server side can cowork with native Pascal apps at client side, this is why I recently have written this zflate unit, because I needed to add a compression to data exchange rountines, and what was available for FPC wasnt enough or was too heavy for my mini-apps.

What other functions would you sugggest to port? Actually there are not that many functions. Im looking at what locutus have:
https://locutus.io/php/
Nothing fancy really.

I would choose
- substr(), instead of copy(s, 5, length(s)-5-5) you could do substr(s, 5, -5)
- all hashing functions, including hash() and hash_hmac()
- fopen(), fwrite(), fread() etc; file_put_contents(), file_get_contents()
- strtotime(), date(), time(), microtime()
- hex2bin(), bin2hex()

Here is substr() snippet ;)

Code: Pascal  [Select][+][-]
  1. program sub;
  2.  
  3. function substr(str: string; offset: integer; len: integer=0): string;
  4. begin
  5.   result := '';
  6.   if str = '' then exit;
  7.   if len = 0 then len := length(str);
  8.   if len > length(str) then len := length(str);
  9.   if (offset > 0) and (len < 0) then len := length(str)-offset+len+1;
  10.   if (offset < 0) and (len < 0) then len := abs(abs(offset)-abs(len));
  11.   if (offset < 0) and (len > 0) then offset := length(str)+offset+1;
  12.   if offset+len > length(str) then len := length(str)-offset+1;
  13.   if len < 1 then exit;
  14.   result := copy(str, offset, len);
  15. end;
  16.  
  17. var
  18.   s: string;
  19.  
  20. begin
  21.   s := 'hello kitty';
  22.  
  23.   writeln('from 3 to the end:            ', substr(s, 3));
  24.   writeln('2 chars starting from 3 char: ', substr(s, 3, 2));
  25.   writeln('all from 3 but last 2 chars:  ', substr(s, 3, -2));
  26.   writeln('last 3 chars                  ', substr(s, -3));
  27.   writeln('first 3 chars:                ', substr(s, 1, 3));
  28.   writeln('all but 3 last chars:         ', substr(s, 1, -3));
  29.   writeln('3 chars starting from char 7: ', substr(s, 7, 3));
  30.  
  31.   readln;
  32. end.

nouzi

  • Sr. Member
  • ****
  • Posts: 306
Re: PHP2Pascal anybody?
« Reply #9 on: February 26, 2024, 02:53:08 pm »
you can replace php with Pascal directly (CGI,FastCGI,PascalScript...etc )

see this link
https://medium.com/swlh/why-is-free-pascal-better-than-php-654d6c569e7b

This is old projects
https://sourceforge.net/projects/pas2php/

this other project write in python
https://github.com/grisuno/pascal2php
My English is  bad
Lazarus last version free pascal last version
Lazarus trunk  free pascal trunk 
System : Linux mint  64bit  Windows 7 64bit

domasz

  • Hero Member
  • *****
  • Posts: 553
Re: PHP2Pascal anybody?
« Reply #10 on: February 26, 2024, 04:05:45 pm »
I wouldnt say PHP programmers will move to Pascal if there were similar functions. Imho every "native compiled language" programmer should be familiar with either PHP or JS+some runtime (such as Node.js).

PHP at server side can cowork with native Pascal apps at client side, this is why I recently have written this zflate unit, because I needed to add a compression to data exchange rountines, and what was available for FPC wasnt enough or was too heavy for my mini-apps.

What other functions would you sugggest to port? Actually there are not that many functions. Im looking at what locutus have:
https://locutus.io/php/
Nothing fancy really.

Some image functions would be nice too. But after the replies here I kinda doubt it makes sense to port those PHP functions to Pascal.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11947
  • FPC developer.
Re: PHP2Pascal anybody?
« Reply #11 on: February 26, 2024, 04:15:27 pm »
- substr(), instead of copy(s, 5, length(s)-5-5) you could do substr(s, 5, -5)

Why is that better than current s.substring(5)

Quote
- all hashing functions, including hash() and hash_hmac()

Mostly in fcl-hash.

Quote
- fopen(), fwrite(), fread() etc; file_put_contents(), file_get_contents()

These are an amalgam of HTTP and file semantics, but both are there in FPC.

Quote
- strtotime(), date(), time(), microtime()

See dateutils

Quote
- hex2bin(), bin2hex()

https://www.freepascal.org/docs-html/rtl/strutils/hextobin.html
https://www.freepascal.org/docs-html/rtl/strutils/bintohex.html


 

TinyPortal © 2005-2018