Will php ever do strong typing?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Will php 6 do strong typing and/or namespaces?

I was shocked to find out today that there are some people who actually
argue that weak typing is somehow better.  I didn't even know there was
a debate.  Shocking.  That's like arguing that square tires are better
than round.

Anyway if anyone knows that php is going to intentionally stay weak in
the future let me know so I can jump ship, thanks,


Re: Will php ever do strong typing?

dterrors@hotmail.com wrote:
Quoted text here. Click to load it

I completely agree. Strong typing makes far more sense due to the
compile-time constraints it enforces. Anyone who thinks otherwise is
lazy, quite frankly, and isn't thinking in terms of long-term
maintainability and debugging.

It also buggers up the fundamental point of OOP, i.e. polymorphism.

Quoted text here. Click to load it

Scripting langauges are not compiled, in general. Therefore most don't
seem to use strong typing, because there's no compiler to catch this
sort of thing. e.g. PHP, Perl, VB, VBscript, Javascript. I don't think
this is likely to change in the future. As Andy says, this would be a
fundamental paradigm shift in any language.

Also, I think languages like PHP are designed for people who don't know
much about "proper" programming. It's designed for people who just want
to throw something together that does the job. No need to worry about
algorithm optimisation, memory allocation or deallocation, hash-table
searching, string handling, type-casting, or indeed typing in general.


Re: Will php ever do strong typing?

Oli Filth wrote (in part):
Quoted text here. Click to load it

Them thar's fight'en words.... :-)

I use PHP because it's easy to program and to get the job done.

<dating myself on>
I have been involved with computers since 1969! Pre Internet, Pre
ARPAnet, Pre OOP, almost Pre CRTs, Pre PCs, Pre MAC, PRE WEB ... the
punch-card era. I've seen the introduction of OOP, I've see "Go To"
less programming, I've seen the "Come From" counter rebellion...
<dating myself off>

Fine, if you don't like PHP because it isn't OOP and strongly typed,
don't use it, but don't expect everyone to agree with you. Find a
programming language you like, use it to interface to the WEB servers
as a CGI. Or, create your own language that can be used with the web
servers, prove to everyone that it is better than what is already out
there. And while you're at it, make sure that it does an excellent job
at catching array overflows and boundary checking. Make sure no one can
use it to write malicious code.


Re: Will php ever do strong typing?

Ken Robinson wrote:
Quoted text here. Click to load it
Quoted text here. Click to load it

I'm not disagreeing with you! I like PHP for the same reason you do: it
gets stuff done *very* quickly.

But you can't deny that PHP hides one hell of a lot of nitty-gritty
low-level (and even standard high-level) stuff from you, so that the
average PHP user can safely assume that, for instance, arrays can
safely be indexed by strings (even though this isn't done natively in
any compiled language that I can think of). But sometimes this stuff is
important. Especially in large, non-trivial systems.

Quoted text here. Click to load it

Again, I'm not disagreeing with you. But from a progammatic point of
view (i.e. "what is my script *actually* doing?"), PHP is not the best
answer. If you are used to a language where compile-time and link-time
catch a large number of syntax errors, silly mistakes and algorithmic
boo-boos (e.g. comparing a string with an integer, which doesn't make
sense in e.g. C), then PHP is going to look pretty basic. If this check
isn't even performed at load-time, then debugging becomes a very
hit-and-miss affair.

And when you consider that many PHP programmers consider eval() to be
an acceptable way of achieving things, the problem becomes even worse.

Like I said before, PHP (along with many scripting languages such as
Javascript and Perl) seems to be designed to get stuff done in an
extremely high-level, abstract way, where even things like object types
are (essentially) irrelevant. Except at run-time, when they bite you in
the arse 6 months down the line if you've screwed up. If only they bit
you in the arse at compile-time (which doesn't exist)...

(P.S. IMO, any language without pointers (and pointer arithmetic) isn't
a real language!!)


Re: Will php ever do strong typing?

Quoted text here. Click to load it

Like say Lisp?


Re: Will php ever do strong typing?

Oli Filth wrote:
Quoted text here. Click to load it

I should probably point out that by this, I do *not* mean that everyone
who uses PHP is some kind of retard. Far from it. I am just stating
that one of its original design objectives was to be a language that
anyone could pick up, with little (or no) programming experience.
Therefore, lots of typical programming issues have been made completely
transparent to the PHP programmer.


Re: Will php ever do strong typing?

Oli Filth wrote:

Quoted text here. Click to load it

"We will encourage you to develop the three great virtues of a programmer:
laziness, impatience, and hubris."

-- LarryWall, ProgrammingPerl (1st edition), O'Reilly & Associates

Sorry, but I just don't get it. Why is enforced strong typing a benefit?

I like the way PHP works. I freely admit there are times when I want to make
sure of the type of a variable but in PHP I can *choose* to do that by
various mechanisms ('===', if ($test==(integer)$test), ...) and if I want
to record the type of a variable I use comments(1).

IMHO Hungarian notation and SOAP do major damage to the readability of code.

Quoted text here. Click to load it
Nope. I don't see that either. If the base types are (to most intents and
purposes) polymorphic, how does that undermine polyorphism in user classes?

IMHO the only design issues with PHP in its current form are:

- namespace collisions - implementing seperate namespaces is one solution to

- erm, that's about it really.

Quoted text here. Click to load it
( not to mention null pointer dereferencing, buffer overflows, failed build

There are no BAD programming languages(2) - just bad programmers ;)

Certainly I want to get things done with a minimum of effort however I have
written network protocol stacks and AI engines in PHP (and no, not because
it was the only programming language I know).

The most expensive component in most computer systems is programmer time.
Have a look at the Great Computer Language Shootout. PHP consistently
scores well in requiring fewer lines of code. It's not the most
minimalistic, but OTOH, I've yet to find someone that thinks PHP is not a
VERY easy language to learn. Add to this the flexibility of what can be
acheived with PHP and it starts to look like a language which excels at
being understood. This kind of transparency (despite my comments below - 1)
is therefore the most valuable asset of any programming language - want to
talk about maintainability and debugging?

But I am more than happy to be educated / proved wrong.


1 - don't even think about posting a reply containing the string
'self-documenting code'
2 - except maybe brainf**k - but it's meant to be bad

Re: Will php ever do strong typing?

IMHO the complexity introduced by namespace is not worth the benefit.
Suddenly people learning PHP have yet another feature to learn. Books
will have an additional chapter. In general PHP code would become more
complicated, since people will start using namespace just because it's
there and not because it's necessary in a given circumstance.

A more useful solution I think would be the ability to create separate
execution contexts, something similiar to the component system in
Flash/Actionscript. You would run a third-party script in its own
context, with separate namespace, variable-space, and settings. That
would eliminate other sorts of conflicts you may encounter in sharing
code, in additional to namespace collisions.

Re: Will php ever do strong typing?

The most expensive component in most computer systems is reliability,
not programmer time.  I'm all in favor of preserving programmer time,
that's why I want strong typing.  If you want to make something
reliable, and you don't have strong typing, then your programmer is
going to spend a hell of a lot more time.  Anyway my whole argument is
summed up in this response on this thread:


Re: Will php ever do strong typing?

You are missing the point abbot dynamic typing - it SAVES programmer time
because you don't have to declare a variable before using it. As for it
allowing errors to fall through - PIFFLE! Any such errors will be trapped
during unit testing. You DO test you code, I presume? Or are you one of
these jokers who assumes that if it compiled OK then it doesn't need

Tony Marston

Quoted text here. Click to load it

Re: Will php ever do strong typing?

Quoted text here. Click to load it

What's so shocking about it? I much prefer a language where I can use
variables without having to declare them first. I also love the ability to
test for and change a variables's type. Very convenient.

Quoted text here. Click to load it

Absolute rubbish!

Quoted text here. Click to load it

Absoute Rubbish!

Quoted text here. Click to load it

Yet it can still be used by people who know a great deal about 'proper'
programming. I used various 2nd, 3rd and4th generation languages for 25+
years before I switched to PHP.

Quoted text here. Click to load it

So what?

Tony Marston

Re: Will php ever do strong typing?

I think people have to agree that PHP gives developers the means to
develop stuff lightning quick, in comparison to say JSP/JavaBeans.

I code in both - personally I much prefer using Java as I like strong
typing and I find the use of objets and classes better.

HOWEVER, PHP development is generally much, much quicker.

I would prefer to use JSP and Java for bigger projects or ones that are
likely to expand over time, however for smaller scale stuff PHP is a
great option because of features such as weak typing (not to mention
all of the HTML/Web related functions built in)

I think a choice of language should comes down to project spec in most


Re: Will php ever do strong typing?


In case some of you are not aware of the difference between strong/weak
and static/dynamic typing and their consequences I found the following
quite enlightening:


- Jacob Atzen

Re: Will php ever do strong typing?

Just to add some more to this list:

Quoted text here. Click to load it


Some are pro some are against as always ;)

Things like this always come down to personal preference.  Me I
completely agree with the first link I posted.  Much of the argument has
been about people not creating programs well....

I think this never solves the problem as in the first link above.  You
need to do solid checking of your programs with unit testing and all the
above.  Most of the errors I see in PHP are logic errors.  You will find
those just about anywhere.


Re: Will php ever do strong typing?

Quoted text here. Click to load it

There may be a third way: meta-code to direct a code checker. Think about
something like this, where the meta-code is given inside comments:

/*.void.*/  function PrintStrings(/*.string.*/ $s, /*.int.*/ $n)
    /*. int $i; .*/
    for($i=1; $i<=$n; $i++){
        echo $s;

The meta-code declare the type of the returned value and the type of
the formal arguments using a syntax symilar to the C language. A source
code checker may use this information to report invalid usages of the
function, exactly as a strong typed language do. This is the direction
I taken developing phplint (www.icosaedro.it/phplint/), a source parser,
semantic and style validator for the PHP language.

Using the meta-code:

- the PHP language do not need to be modified
- the PHP interpreter do not need to be modified
- the meta-code may be added to the source after the prototyping phase,
  just to check the source before the final release

/_|_\  Umberto Salsi
\/_\/  www.icosaedro.it

Re: Will php ever do strong typing?

Umberto Salsi wrote:
Quoted text here. Click to load it

This looks like it could be perfect for what I need.  But does it only
work with base types like string and int, or can it check object types
that I define?

/*MyObject*/ function getthing(/*MyThing*/ mt, /*MyArrayList/* arl) {

etc etc ?

Re: Will php ever do strong typing?

dterrors@hotmail.com wrote:

Quoted text here. Click to load it

Currently only base-types are allowed: boolean, int, float, number,
int, float, string, array, resource, mixed, void.

Classes are still to be implemented in phplint: they are parsed, but can't be
used in meta-declarations. I'm planning to cover classes and methods soon,
so that class names may be used in declarations just as expected.

/_|_\  Umberto Salsi
\/_\/  www.icosaedro.it

Re: Will php ever do strong typing?

Quoted text here. Click to load it

That's very interesting, but www.phpdoc.org also defines meta-code inside
comments. Do I have to declare every variable, function, parameter twice,
i.e once for phpline and once for phpdoc or more awful will the comment of
one type confuse the other engine?


Re: Will php ever do strong typing?

Quoted text here. Click to load it

Nothing need to be declared twice: the phplint meta-code is "orthogonal"
to the DocBlock meta-code, since they use different conventions on
multi-line comments. The phplint meta-code just add some info for the

Sure, it should be better an integrated system that include either
meta-code for the validator and meta-code for the documentation system.
By now I'm concentrating on extensions to the PHP language that are
usefull for the validator. The documentation capabilities may be an
interesting additional feature for phplint, but this is not the primary
goal of the validator.

/_|_\  Umberto Salsi
\/_\/  www.icosaedro.it

Re: Will php ever do strong typing?

Great, just what we need, flame bait.

Site Timeline