Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Php 7 i PHPStorm 10
Fred1485
post
Post #1





Grupa: Zarejestrowani
Postów: 361
Pomógł: 22
Dołączył: 10.02.2015

Ostrzeżenie: (0%)
-----


Chciałem pobawić się z PHP7, pobrałem testową wersję PHPStorm 10. Interpreter dodałem, więc efekty moich wypocin pisane w PHP7 w przeglądarce działają, ale w IDE wyrzuca dziwne błędy, mianowicie:

  1. public function __construct (array $resources, array $requirements, int $destruction)
  2. {
  3. $this->resources = $resources;
  4. $this->requirements = $requirements;
  5. $this->destruction = $destruction;
  6. }


Rzutuję $destruction na int, konkretyzując obiekt dostaję błąd:

  1. $level = new \Game\Fields\DeepDeath([], [], 30);


Błąd dotyczy tego, że konstruktor oczekiwał nie int a obiektu o typie int. Już to drażni w oczy, mając metodę:

  1. public function getDestruction (): int
  2. {
  3. return $this->destruction;
  4. }


I wywołanie:

  1. echo $level->getDestruction();


Otrzymuję kolejny błąd, jak się można domyślić, że nie mam metody __toString w obiekcie int. IDE bierze wartość skalarną jakby był to obiekt. Dodam, że w przeglądarce działa wszystko. Może trzeba w opcjach przełączyć coś?

Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Fred1485
post
Post #2





Grupa: Zarejestrowani
Postów: 361
Pomógł: 22
Dołączył: 10.02.2015

Ostrzeżenie: (0%)
-----


Już prostuję, w IDE pokazuję błąd, natomiast w przeglądarce wszystko działa (IMG:style_emoticons/default/wink.gif) W opcjach mam ustawiony interpreter na PHP7 oraz wersję także na 7.

  1. namespace Game\Fields;
  2.  
  3.  
  4. abstract class Field
  5. {
  6. protected $resources = [];
  7.  
  8. protected $requirements = [];
  9.  
  10. protected $destruction;
  11.  
  12. public function __construct (array $resources, array $requirements, int $destruction)
  13. {
  14. $this->resources = $resources;
  15. $this->requirements = $requirements;
  16. $this->destruction = $destruction;
  17. }
  18.  
  19. public function getResources (): array
  20. {
  21. return $this->resources;
  22. }
  23.  
  24. public function getRequirements (): int
  25. {
  26. return $this->requirements;
  27. }
  28.  
  29. public function getDestruction (): int
  30. {
  31. return $this->destruction;
  32. }
  33. }
  34.  
  35. class DeepDeath extends Field {}
  36.  
  37. class MysteryDark extends Field {}
  38.  
  39. class SunEnd extends Field {}


Wywołanie:

  1. declare(strict_types=1);
  2.  
  3. require_once __DIR__ . '/Fields/Fields.php';
  4.  
  5. $level = new \Game\Fields\DeepDeath([], [], 30);
  6.  
  7. echo $level->getDestruction();


Sorki za niską rozdzielczość (IMG:style_emoticons/default/tongue.gif)

http://abload.de/img/beztytuuhhqif.png
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 28.12.2025 - 17:19