Preserve empty-string env() defaults and support nested function-calls - #41
Merged
JohnathonKoster merged 1 commit intoJul 19, 2026
Merged
Conversation
… args
FunctionWriter::convertToArgs() dropped any argument that was an empty
string (mb_strlen($arg) === 0), treating it the same as an omitted
argument. That meant f()->env('KEY', '') silently rendered as
env('KEY') instead of env('KEY', ''), losing an intentionally-empty
default.
It also unconditionally coerced every argument through gettype()-based
scalar conversion, which broke for arguments that are themselves an
Expr (e.g. building env('X', base_path('content')) via
f()->env('X', f()->basePath('content'))) - there was no way to nest
one function-call builder result inside another.
Fixes:
- Only treat an explicit null as "omit this argument"; empty strings
are now passed through as real Arg values.
- FunctionWriter::arg() now passes an Expr argument straight through
instead of trying to scalar-convert it, enabling nested calls.
- The single-arg path helpers (resourcePath, storagePath, etc.) now
default to null so `f()->resourcePath()` still produces a bare
resource_path() call - the same result the old empty-string
behavior gave you, but as an explicit "no argument" rather than a
special-cased empty string.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
FunctionWriter::convertToArgs()silently drops any argument that's an empty string, treating it the same as an omitted one:That's indistinguishable from actually wanting
env('SOME_PATH'), so there was no way to write a genuinely-empty default via the fluent API.Separately, every argument was coerced through
gettype()-based scalar conversion, which breaks the moment an argument is itself a built expression rather than a plain scalar:That meant you couldn't build something like
env('CONTENT_PATH', base_path('content'))through the fluent API at all — you had to drop into rawPhpParsernode construction by hand.Solution
convertToArgs()now only treats an explicitnullas "omit this argument" — empty strings pass through as real values.FunctionWriter::arg()now checks$arg instanceof Exprfirst and passes it straight through, instead of trying to scalar-convert it. This is what makes nesting work:$f->basePath('content')already returns aFuncCall(anExpr), so it now flows straight into the outerenv()call's args.resourcePath,storagePath,basePath, etc.) now default tonullinstead of requiring an argument. That preserves the "call with no arguments" result (f()->resourcePath()→resource_path()) — previously the only way to get that was to pass'', which is exactly the behavior being fixed.Testing
Three new cases in
LaravelFunctionCallTest: an empty-string default is preserved, a path helper called with no arguments renders as a bare call, and abasePath()call nested as anenv()default renders correctly. All pre-existing tests still pass (2 unrelated, pre-existing closure-formatting failures aside, confirmed present before this change too).