Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Python has literally all of those things, and has been strongly (but dynamically) type from the very beginning. PHP is still weakly typed today. This code doesn't raise a warning or anything:

  $ php --version
  PHP 7.3.11 (cli) (built: Jun  5 2020 23:50:40) ( NTS )
  Copyright (c) 1997-2018 The PHP Group
  Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies
  
  $ php -r 'echo "123" + 45;'                                                                
  168
Contrast with Python:

  Python 3.8.3 (default, Jun  1 2020, 10:55:34)
  >>> "123" + 45
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  TypeError: can only concatenate str (not "int") to str


These examples are not about strong typing, but about type juggling. Strong typing is this:

  declare(strict_types=1);

  use \Domain\SomeItem;
  use \Domain\SomeItemId;
  use \Domain\SomeItemSpec;

  abstract class SomeItemRepo {
    public function GetOneByID(SomeItemId $id): SomeItem;
    /*
     * Still hacky
     *
     * @param []SomeItemSpec $specs
     *
     * @return []SomeItem
     */
    public function GetManyBySpecs(array $specs): array; 
  }


That's an example of strong typing specific to PHP, then, and not used in the rest of computer science. What you're describing there is usually known as static typing, which Python also supports.


No, types are checked at runtime in PHP. You can also use static types with docblocks and use static analysis tools, and both play complement eachother.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: