Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I assign a literal value? #424

Open
ejunker opened this issue May 25, 2016 · 6 comments
Open

How do I assign a literal value? #424

ejunker opened this issue May 25, 2016 · 6 comments

Comments

@ejunker
Copy link

ejunker commented May 25, 2016

I want to hard code a literal value. Here is a minimal example:

$fm->define('Resume')->setDefinitions([
    'salary' => 'd',
]);

The problem is I also have a global function d() and it calls the d() function instead of just using the literal value 'd'. Is there a way to assign literal string values?

@GrahamCampbell
Copy link
Member

Hmm, that is a bit of a problem. The issue is the string d is callable on your machine.

@GrahamCampbell
Copy link
Member

One way to force the string would be to do:

$fm->define('Resume')->setDefinitions([
    'salary' => function () { return 'd'; },
]);

@ejunker
Copy link
Author

ejunker commented May 25, 2016

That would work but it is a bit verbose. As a user I would expect a literal string to assign a literal string. It would be a breaking change but maybe in the future it could be changed so that if you want to call a callable that you would have to do something like like this.

$fm->define('Foo')->setDefinitions([
    'bar' => $fm->call('myCallable'),
]);

@GrahamCampbell
Copy link
Member

I wonder if I could refactor the generator stuff so that people could choose to disable callables. Would that work for you. In other words, only support closures rather than callables, as an option.

@ejunker
Copy link
Author

ejunker commented May 25, 2016

That would work. If callables were disabled I still like the idea of having a helper method that you could pass a string and it would return a closure that calls the callable. Like the $fm->call() in my previous example.

@GrahamCampbell
Copy link
Member

I'll have a think how I can make this work so it's really nice to use.

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

No branches or pull requests

2 participants