Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

is_string()

Check for a native string even when it is empty, binary or contains digits only.

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

Syntax

is_string(mixed $value): bool

Check for a native string even when it is empty, binary or contains digits only. An object whose __toString method produces text is still an object and fails. Validate the type before applying an operation that expects stored bytes.

Signature

is_string(mixed $value): bool

Example output

[true,true,true,false,false]

Examples

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

Result

[true,true,true,false,false]

Sources