Skip to content

Conversation

@CybotTM
Copy link
Contributor

@CybotTM CybotTM commented Jan 2, 2026

Summary

The tempnam() call in PlantumlRenderer::render() uses a subdirectory of sys_get_temp_dir() that may not exist, which triggers a PHP E_NOTICE:

Notice: tempnam(): file created in the system's temporary directory

This notice can appear in rendered documentation output when error reporting includes E_NOTICE.

Changes

  • Create the temp subdirectory if it doesn't exist before calling tempnam()
  • Add dependency injection for temp directory path (optional constructor parameter, defaults to sys_get_temp_dir() . '/phpdocumentor')
  • Add regression test using injected temp directory for proper isolation

Test plan

  • Configure guides to use local PlantUML binary (renderer="plantuml")
  • Ensure /tmp/phpdocumentor does not exist
  • Render documentation with a .. uml:: directive
  • Verify no E_NOTICE is emitted

Moved from phpDocumentor/guides-graphs#2

@CybotTM CybotTM force-pushed the bugfix/plantuml-tempnam-notice branch from 2cc375c to eae4d50 Compare January 2, 2026 21:02
PUML;

$pumlFileLocation = tempnam(sys_get_temp_dir() . '/phpdocumentor', 'pu_');
$tempDir = sys_get_temp_dir() . self::TEMP_SUBDIRECTORY;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to inject the directory used by this class, I remember when I wrote this I didn't write a test because it was hard to run this in isolation. Injecting the path can be done via the constructor and would allow us to use vfsStream to fake the filesystem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion for testability! This was initially out of scope for the bugfix, but I can include it if you'd like. Let me know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can do that, that would be great.

Please keep in mind that we do not want to be backwards compatible. So any new constructor argument must have a default value. Which could still be sys_get_tmp_dir.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can do that, that would be great.

Please keep in mind that we do not want to be backwards compatible. So any new constructor argument must have a default value. Which could still be sys_get_tmp_dir.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep in mind that we do not want to be backwards compatible.

I assume a typo here, you want to be BC, right? Otherwise the new constructor argument would not need to have a default value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks

@CybotTM CybotTM force-pushed the bugfix/plantuml-tempnam-notice branch 2 times, most recently from 8105982 to e6a7378 Compare January 3, 2026 21:20
@CybotTM CybotTM marked this pull request as draft January 4, 2026 12:11
The tempnam() call uses a subdirectory of sys_get_temp_dir() that may
not exist, which triggers a PHP E_NOTICE when the directory is missing.
PHP then falls back to the system temp directory, but the notice can
appear in rendered output.

This creates the directory if it doesn't exist before calling tempnam(),
preventing the notice.

Also extracts the temp subdirectory path to a public constant so tests
can reference it directly, ensuring they stay in sync with the
implementation.
Adds a unit test to verify that the temp directory is created
before calling tempnam(), preventing the E_NOTICE regression.
…erer

Allow temp directory to be injected via constructor for better
testability and flexibility. Falls back to system temp directory
with /phpdocumentor subdirectory if not provided.
@CybotTM CybotTM force-pushed the bugfix/plantuml-tempnam-notice branch from e6a7378 to a40aec7 Compare January 4, 2026 12:15
@CybotTM CybotTM changed the title [BUGFIX] Ensure temp directory exists before calling tempnam() [BUGFIX] Ensure temp directory exists before calling tempnam() + DI support Jan 4, 2026
@CybotTM CybotTM marked this pull request as ready for review January 4, 2026 15:37
@jaapio jaapio merged commit 3dabf92 into phpDocumentor:main Jan 4, 2026
102 of 112 checks passed
@jaapio
Copy link
Member

jaapio commented Jan 4, 2026

Thanks for your help.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants