Skip to content

Conversation

@takaram
Copy link
Contributor

@takaram takaram commented Nov 24, 2025

Closes phpstan/phpstan#13089

Some ctype functions asserts non-falsy-string, while others asserts non-empty-string.

Test script to see the functions' return value when `''` or `'0'` given
<?php

$ctypeFuncs = array_filter(
	get_defined_functions()['internal'],
	fn (string $name) => str_starts_with($name, 'ctype_'),
);

echo "func name   \t''\t'0'\n";
foreach ($ctypeFuncs as $func) {
	printf(
		"%-12s\t%s\t%s\n",
		$func,
		var_export($func(''), true),
		var_export($func('0'), true),
	);
}

Result:

func name       ''      '0'
ctype_alnum     false   true
ctype_alpha     false   false
ctype_cntrl     false   false
ctype_digit     false   true
ctype_lower     false   false
ctype_graph     false   true
ctype_print     false   true
ctype_punct     false   false
ctype_space     false   false
ctype_upper     false   false
ctype_xdigit    false   true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ctype_alnum should narrow given input at least as non-empty-string

1 participant