Quantcast
Viewing latest article 2
Browse Latest Browse All 2

Programistyczny fail: “argument musi być stringiem, przekazano string”

Dosyć ciekawy błąd przytrafił się koledze piszącemu w PHP:

Catchable fatal error: 
Argument 1 passed to foo() must be an instance of string, string given, called in 
/Users/madmatt/Documents/Projects/foobar/

dosyć mocny WTF. Kod, który to powoduje:

function foo(string $s)
{
}
foo("bar");

Próbujemy tutaj ograniczyć przyjmowane argumenty przez funkcję foo do zmiennych typu string. Co ciekawe, to nie bug, tylko feature (lub też brak tegoż feature). Okazuje się, że php tego nie obsługuje. Powie nam to linijka na samym końcu rozdziału o Type Hinting:

Type Hints can only be of the object and array (since PHP 5.1) type. Traditional type hinting with int and string isn’t supported.

Czyli tablice, klasy – tak, podstawowe typy nie?
Too bad, ale z treścią błędu mogli się bardziej postarać. A to jeszcze inny klasyk z PHP:

Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM in 
Command line code on line 1

To po hebrajsku. Znacie inne tego typu niespodzianki rodem z PHP?


Viewing latest article 2
Browse Latest Browse All 2

Trending Articles


TRX Antek AVT - 2310 ver 2,0


Автовишка HAULOTTE HA 16 SPX


POTANIACZ


Zrób Sam - rocznik 1985 [PDF] [PL]


Maxgear opinie


BMW E61 2.5d błąd 43E2 - klapa gasząca a DPF


Eveline ➤ Matowe pomadki Velvet Matt Lipstick 500, 506, 5007


Auta / Cars (2006) PLDUB.BRRip.480p.XviD.AC3-LTN / DUBBING PL


Peugeot 508 problem z elektroniką


AŚ Jelenia Góra