Skip to content

docs: [File Instance] RunTimeException if file does not exist#9037

Merged
kenjis merged 4 commits intocodeigniter4:developfrom
christianberkman:docs-file-getsize
Jul 25, 2024
Merged

docs: [File Instance] RunTimeException if file does not exist#9037
kenjis merged 4 commits intocodeigniter4:developfrom
christianberkman:docs-file-getsize

Conversation

@christianberkman
Copy link
Copy Markdown
Contributor

Description
File::getSize and File::getSizeByUnit() may cause a RunTimeException if the file does not exist or an error occurs. From the original docblock my expectation was that the functions would return false on an error (e.g. file does not exist), but the called SplFileInfo::getSize() throws a runtime error if the file does not exist.

From the PHP docs

The filesize in bytes on success, or false on failure.
A RuntimeException will be thrown if the file does not exist or an error occurs.

From the PHP docs it is not quite clear to me when to expect an exception and when to expect false.

If return of false on any error is desired, I am happy to submit a PR to catch the exception.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added the documentation Pull requests for documentation only label Jul 10, 2024
@kenjis kenjis merged commit 9597237 into codeigniter4:develop Jul 25, 2024
@kenjis
Copy link
Copy Markdown
Member

kenjis commented Jul 25, 2024

@christianberkman Thank you!

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

Labels

documentation Pull requests for documentation only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants