🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.vms
Article #165

Re: PHP "Features"

#165
From: Arne Vajhøj
Date: Sat, 14 Nov 2026 18:23
308 lines
9153 bytes
On 10/27/2026 7:35 PM, Arne Vajhøj wrote:
> If you want to go the simpler route, then I will suggest an
> unusual tech stack.
> 
> JSP with JSTL as view. That mean all tags no script snippets
> in view - tags is also some sort of code but very structured.
> 
> Groovy grovelets as backend code. It is just another script
> language, but:
> * most of the easiness you expect from a script language
> * no funkyness with ==
> * optional typing but if a type is specified then it is enforced - it
>    is not just a hint

Here comes a little comparison with Python and PHP.

Tested with:
* Python 3.10
* PHP 8.1
* Groovy 4.0

Not latest and greatest but what I have on my 9.2-3 system.

Let us look at simple assignment.

$ type asg.py
iv = 123
sv = 'ABC'
print('%s : %d, %s : %s' % (type(iv), iv, type(sv), sv))
iv = 'DEF'
sv = 456
print('%s : %s, %s : %d' % (type(iv), iv, type(sv), sv))
$ python asg.py
<class 'int'> : 123, <class 'str'> : ABC
<class 'str'> : DEF, <class 'int'> : 456
$ type asgtyp.py
iv: int = 123
sv: str = 'ABC'
print('%s : %d, %s : %s' % (type(iv), iv, type(sv), sv))
iv = 'DEF'
sv = 456
print('%s : %s, %s : %d' % (type(iv), iv, type(sv), sv))
$ python asgtyp.py
<class 'int'> : 123, <class 'str'> : ABC
<class 'str'> : DEF, <class 'int'> : 456
$ type asg.php
<?php

$iv = 123;
$sv = "ABC";
echo sprintf("%s : %d, %s : %s\n", gettype($iv), $iv, gettype($sv), $sv);
$iv = "DEF";
$sv = 456;
echo sprintf("%s : %s, %s : %d\n", gettype($iv), $iv, gettype($sv),$sv);

?>
$ php asg.php
integer : 123, string : ABC
string : DEF, integer : 456
$ type asg.groovy
iv = 123
sv = "ABC"
printf("%s : %d, %s : %s\n", iv.getClass().name, iv, sv.getClass().name, sv)
iv = "DEF"
sv = 456
printf("%s : %s, %s : %d\n", iv.getClass().name, iv, sv.getClass().name, sv)
$ groovy asg.groovy
java.lang.Integer : 123, java.lang.String : ABC
java.lang.String : DEF, java.lang.Integer : 456
$ type asgtyp.groovy
int iv = 123
String sv = "ABC"
printf("%s : %d, %s : %s\n", iv.getClass().name, iv, sv.getClass().name, sv)
iv = "DEF"
sv = 456
printf("%s : %s, %s : %d\n", iv.getClass().name, iv, sv.getClass().name, sv)
$ groovy asgtyp.groovy
java.lang.Integer : 123, java.lang.String : ABC
Caught: org.codehaus.groovy.runtime.typehandling.GroovyCastException: 
Cannot cast object 'DEF' with class 'java.lang.String' to class 'int'
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot 
cast object 'DEF' with class 'java.lang.String' to class 'int'
         at ASGTYP.run(ASGTYP.GROOVY:4)

We see that:
* Python without type hint, Python with type hint, PHP and Groovy 
without type
   happily allows variables changing type with assignment [BAD]
* Groovy with type gives an error when assigning a wrong type [GOOD]

Let us look at function call.

$ type fc.py
def f(v):
     vtyp = type(v)
     print(f"{vtyp} : {v}")

f(123)
f("123")
f("ABC")
$ python fc.py
<class 'int'> : 123
<class 'str'> : 123
<class 'str'> : ABC
$ type fctyp.py
def f(v: int):
     vtyp = type(v)
     print(f"{vtyp} : {v}")

f(123)
f("123")
f("ABC")
$ python fctyp.py
<class 'int'> : 123
<class 'str'> : 123
<class 'str'> : ABC
$ type fc.php
<?php

function f($v) {
     $vtyp = gettype($v);
     echo "$vtyp : $v\r\n";
}

f(123);
f("123");
f("ABC");

?>
$ php fc.php
integer : 123
string : 123
string : ABC
$ type fctyp.php
<?php

function f(int $v) {
     $vtyp = gettype($v);
     echo "$vtyp : $v\r\n";
}

f(123);
f("123");
f("ABC");

?>
$ php fctyp.php
integer : 123
integer : 123
PHP Fatal error:  Uncaught TypeError: f(): Argument #1 ($v) must be of 
type int, string given, called in /disk2/arne/typ/fctyp.php on line 10 
and defined in /disk2/arne/typ/fctyp.php:3
Stack trace:
#0 /disk2/arne/typ/fctyp.php(10): f('ABC')
#1 {main}
   thrown in /disk2/arne/typ/fctyp.php on line 3

Fatal error: Uncaught TypeError: f(): Argument #1 ($v) must be of type 
int, string given, called in /disk2/arne/typ/fctyp.php on line 10 and 
defined in /disk2/arne/typ/fctyp.php:3
Stack trace:
#0 /disk2/arne/typ/fctyp.php(10): f('ABC')
#1 {main}
   thrown in /disk2/arne/typ/fctyp.php on line 3
$ type fctypx.php
<?php

declare(strict_types=1);

function f(int $v) {
     $vtyp = gettype($v);
     echo "$vtyp : $v\r\n";
}

f(123);
f("123");
f("ABC");

?>
$ php fctypx.php
integer : 123
PHP Fatal error:  Uncaught TypeError: f(): Argument #1 ($v) must be of 
type int, string given, called in /disk2/arne/typ/fctypx.php on line 11 
and defined in /disk2/arne/typ/fctypx.php:5
Stack trace:
#0 /disk2/arne/typ/fctypx.php(11): f('123')
#1 {main}
   thrown in /disk2/arne/typ/fctypx.php on line 5

Fatal error: Uncaught TypeError: f(): Argument #1 ($v) must be of type 
int, string given, called in /disk2/arne/typ/fctypx.php on line 11 and 
defined in /disk2/arne/typ/fctypx.php:5
Stack trace:
#0 /disk2/arne/typ/fctypx.php(11): f('123')
#1 {main}
   thrown in /disk2/arne/typ/fctypx.php on line 5
$ type fc.groovy
def f(v) {
     vtyp = v.getClass().name
     println("$vtyp : $v")
}

f(123)
f("123")
f("ABC")
$ groovy fc.groovy
java.lang.Integer : 123
java.lang.String : 123
java.lang.String : ABC
$ type fctyp.groovy
def f(int v) {
     vtyp = v.getClass().name
     println("$vtyp : $v")
}

f(123)
f("123")
f("ABC")
$ groovy fctyp.groovy
java.lang.Integer : 123
Caught: groovy.lang.MissingMethodException: No signature of method: 
FCTYP.f() is applicable for argument types: (String) values: [123]
Possible solutions: f(int), is(java.lang.Object), NV(java.lang.Object), 
SV([Ljava.lang.Object;), run(), run()
groovy.lang.MissingMethodException: No signature of method: FCTYP.f() is 
applicable for argument types: (String) values: [123]
Possible solutions: f(int), is(java.lang.Object), NV(java.lang.Object), 
SV([Ljava.lang.Object;), run(), run()
         at FCTYP.run(FCTYP.GROOVY:7)

We see that:
* Python without type hint, Python with type hint, PHP without type hint and
   Groovy without type happily allows calls with any data type [BAD]
* PHP with type hint but no strict_types=1 gives an error when called with a
   value that cannot be converted to correct type but does automatic 
conversion
   when called with a value that can be converted to correct type 
[QUESTIONABLE]
* PHP with type hint plus strict_types=1 and Groovy with type gives an error
   when called with wrong type [GOOD]

Let us look at function overload.

$ type fol.py
def f(v: int):
     print(f"int : {v}")

def f(v: str):
     print(f"str : {v}")

f(123)
f("ABC")
$ python fol.py
str : 123
str : ABC
$ type fol.php
<?php

function f(int $v) {
     echo "int : $v\r\n";
}

function f(string $v) {
     echo "string : $v\r\n";
}

f(123);
f("ABC");

?>
$ php fol.php
PHP Fatal error:  Cannot redeclare f() (previously declared in 
/disk2/arne/typ/fol.php:3) in /disk2/arne/typ/fol.php on line 8

Fatal error: Cannot redeclare f() (previously declared in 
/disk2/arne/typ/fol.php:3) in /disk2/arne/typ/fol.php on line 8
$ type fol.groovy
def f(int v) {
     println("int : $v")
}

def f(String v) {
     println("String : $v")
}

f(123)
f("ABC")
$ groovy fol.groovy
int : 123
String : ABC

We see that:
* Python just let the last function overwrite the previous one and 
ignores type
   hints [BAD]
* PHP gives an error [ACCEPTABLE]
* Groovy it works [GOOD]

So if you want a script language with type safety, then:
   Python - definitely avoid
   PHP - getting better with newer features
   Groovy - use types and you got what you want

And I know you can code in Groovy.  :-)

Arne

Technical Details
Message-ID: <11da8tp$25hpa$7@dont-email.me>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11bcbi1$k068$1@dont-email.me> <nk2bhaF5j2sU1@mid.individual.net> <11bh3ei$19g$1@reader2.panix.com> <11bi7bg$2mdi4$1@dont-email.me> <11bipfv$190$1@reader2.panix.com> <11bquar$1pp8h$3@dont-email.me> <11brcg1$1vuaq$1@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Arne Vajhøj <arne@vajhoej.dk>
Newsgroups: comp.os.vms
Subject: Re: PHP "Features"
Date: Sat, 14 Nov 2026 13:23:35 -0500
Organization: A noiseless patient Spider
Lines: 308
Message-ID: <11da8tp$25hpa$7@dont-email.me>
References: <11bcbi1$k068$1@dont-email.me> <nk2bhaF5j2sU1@mid.individual.net>
 <11bh3ei$19g$1@reader2.panix.com> <11bi7bg$2mdi4$1@dont-email.me>
 <11bipfv$190$1@reader2.panix.com> <11bquar$1pp8h$3@dont-email.me>
 <11brcg1$1vuaq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 14 Nov 2026 18:22:50 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2279210"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19lPrU65vysDJ7YnQxC6Hs0bSC0rRsNQQE="; posting-host="61d91260449277eb6ca39880cc2a736b"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:g7QI4DtVsU5/TfELYUavsvm2FlE= sha256:53Dt6pa11nnoHK74cBq7lHhLahsOQQ0Wx3NyTOZDzt0=
	sha1:EFkty7c50wapl2PLr/1gC+s042U= sha256:xdjNeSq2l09u+sEzkwQiKZOdq1/ZW9vntro3dYYdQpY=
Content-Language: en-US
In-Reply-To: <11brcg1$1vuaq$1@dont-email.me>