What is the lstat() function in PHP?

In PHP, the lstat() function is used to return information about a file or a symbolic link. It provides statistics about the particular file provided in the argument.

Syntax

lstat(string $filename): array|false

Parameters

  • filename: The path to the file or symbolic link as a string.

Return value

lstat() returns an array that includes information on the following elements upon success. It returns false on failure.

Note: This function is similar to stat(), except that if the file parameter is a symbolic link, the status of the symlink is returned instead of the status of the file pointed to by the symlink.

Numeric

Associative

Description

0

dev

device number

1

ino

inode number

2

mode

inode protection mode

3

nlink

number of links

4

uid

userid of owner

5

gid

groupid of owner

6

rdev

device type, if inode device

7

size

size in bytes

8

atime

time of last access (Unix timestamp)

9

mtime

time of last modification (Unix timestamp)

10

ctime

time of last inode change (Unix timestamp)

11

blksize

blocksize of filesystem IO

12

blocks

number of 512-byte blocks allocated

Code

The code below shows the usage of lstat(). It also compares the results of lstat() to stat().

main.php
test.php
<?php
symlink('test.php', 'test');
print_r("\n*****stat*****\n");
print_r(stat('test'));
print_r("\n*****lstat*****\n");
print_r(lstat('test'));
?>

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved