Baza wiedzyCentrum egzaminacyjne
PLPolski
Wybierz język13

CKTIS / PHP

is_string()

Rozpoznaje napis także wtedy, gdy jest pusty, binarny lub zawiera wyłącznie cyfry.

Wersja: PHP 8.4; repository runtime, production runtime not attested

Składnia

is_string(mixed $value): bool

Rozpoznaje napis także wtedy, gdy jest pusty, binarny lub zawiera wyłącznie cyfry. Obiekt z metodą __toString daje false. Taka kontrola chroni operację oczekującą bezpośrednio zapisanych bajtów.

Sygnatura

is_string(mixed $value): bool

Wynik przykładu

[true,true,true,false,false]

Przykłady

<?php
class Label { public function __toString(): string { return "12"; } }
echo json_encode(array_map("is_string", ["", "\0", "12", 12, new Label()]));

Wynik

[true,true,true,false,false]

Źródła