Level 15
Place the condition outside of the strlen function call.
return strlen($value) == 0;
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Why it does not give an error when everything is okay? my code validator class
<?php
class Validator
{
public static function string($value)
{
return strlen($value == 0);
}
}
?>
my validate file
require 'Validator.php';
$config = require('config.php');
$db = new Database($config['database']);
// $validator = new Validator();
$heading = 'Create Note';
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
// echo var_dump($_POST['body']);
$errors = [];
if (Validator::string($_POST['body'])) {
$errors['body'] = 'A body is required';
}
Place the condition outside of the strlen function call.
return strlen($value) == 0;
Please or to participate in this conversation.