Re: Re: Re: Re: php-cli vs python

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Nathan Nobbe dedi ki:

>> Admittedly, there are some annoying features of PHP, the most
>> annoying one being its "dynamic" typing (opposed to "weak" typing).
> 
> I think its worth mentioning that 'dynamic' and 'weak' typing both refer
> to type checking, yet they refer to different aspects of type checking.
> a lanuguage is either dynamically or statically typed and either weakly
> or strongly typed, going by wikipedia:
> http://en.wikipedia.org/wiki/Type_checking#Type_checking
> 
> and PHP is supposedly dynamically, weakly typed
> http://en.wikipedia.org/wiki/Php

My sloppy terminology use. Still not sure about the precise terminology,
but what I meant might be called as "unavoidable dynamic casting". For
instance, I once wanted to XOR a 128 bit binary string variable with a 128
bit binary constant string. Unable to express a binary string in a
straightforward way, I resorted to "pack" it like this:

$key = pack("N*", 0x12345678, 0x9abcdef0, 0x87654321, 0x0fedcba9);

Well, second and third 32-bit hex values were automatically converted by
PHP to float, before packing, because PHP tries to cast them into signed
32-bit integers, which can't be represented with, as they're above
0x7fffffff (2^31-1). So, PHP casts them to floats. As a workaround I had
to use modulo-8 values for the top hex digits. (E.g. 0x1abcdef0 instead of
0x9abcdef0).

No way to say "Just take these bytes and pack them together, as is". Every
operation goes through PHP's own type juggling pipe. I can do explicit
casting, but not always - as in the example above. (It's possibly just my
lack of grip on PHP).

I wish PHP6 would bring along a feature to arbitrarily control or disable
dynamic casting. Without auto-casting, treating everything as byte
strings. E.g. if the user says

$x = "A" + 5;

and if auto casting is disabled, then just adding their internal
representations (0x41 + 0x05 giving 0x46) like an assembler. Sometimes I
want to take all the responsibility of disabling typing, and instruct
PHP "please do it as is, and let me worry if it makes sense or not".

Perhaps there's already a way to do this?..

Kind regards,
-- 
Abdullah Ramazanoglu
aramazan ÄT myrealbox D0T cöm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux