File::jsonSerialize()

Returns the data to be serialized as JSON.

Table of Contents
  1. Description
  2. Example

Description

File::jsonSerialize(): mixed;

This method is a requirement to be able to implement the JsonSerializable interface and aims to make the data convertable to JSON. You won’t use this method directly, the json_encode() function will call this method automatically.

Example

$file = new File('.\path\to\file.txt');

echo json_encode($file); // Returns `'{"path":".\path\to\file.txt"}'` if file exists, returns `false` if file does not exist.

File::jsonSerialize()

Returns the data to be serialized as JSON.

File::size()

Gets the file sizes in human readable string format.