Level 29
string
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am creating my personal Todo App using OOP PHP and Composer Autoload.
I am using Interface to Declare the Classes.
In some of my classes has return type json_encode()
LIKE THIS:
<?php
include ("../db.php");
class ActiveTodo {
private $connection_string ;
public function getActiveList() {
$sql = "SELECT * FROM todo WHERE todo_status = 0";
$result = mysqli_query($this->connection_string, $sql);
return $result ? $result->fetch_all(MYSQLI_ASSOC) : [];
}
}
$todo = new ActiveTodo;
echo json_encode($todo->getActiveList());
?>
I have declared Interface like this.
<?php
namespace todo\app;
interface ILastid extends IDb{
public function fetchLastId();
}
Now what will be the return type for json_encode()? If we have int return then we gave:
public function getId() : int;
Please or to participate in this conversation.