202 reputation
16
bio website r.je
location UK
age 28
visits member for 1 year, 10 months
seen Sep 3 at 8:22

Apr
9
comment Is it wrong to have HTML strings within PHP objects, or is it only wrong in controllers?
Ignoring the model containing a render method, having the controller fetch the model and pass data to the view is not MVC anyway. In MVC the view has direct access to the model.
Mar
3
awarded  Student
Mar
2
awarded  Yearling
Mar
2
revised Constants vs public properties for configuration
edited tags
Mar
2
asked Constants vs public properties for configuration
Nov
8
awarded  Critic
Dec
13
awarded  Commentator
Dec
13
comment OO PHP static keyword, should I use it?
To add a little bit more regarding TDD: it's not so much that the static method may fail, it's that the static method may contain a bug. If it's giving the wrong output for a given input then the code being tested may work perfectly but give inconsistent results. Debugging this becomes more difficult because you need to trace the execution to where the bug is occurring. In TDD this is avoided by testing pieces of code in complete isolation, if the test fails then the developer should know instantly which lines of code to debug without having to trace the execution.
Dec
12
awarded  Supporter
Dec
12
comment Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
I should clarify this as as well: the only reason that the controller has access to the repository in this scenario is because you have to convert user_id to a user object somewhere. In a desktop application this would all be handled in the model because it's able to be persistent. On the web persistence isn't possible so some concessions must be made.
Dec
12
comment Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
That's display logic. In this example, the controller never needs access to the birthday/validation date. The controller would set the model's state: "This is the user that is being dealt with" and the View would request the user from the model. The fact that the view only needs an arbitrary piece of information from the user is no concern of the controller's or model's. This way, the controller and model are reusable with any number of views incidental of what data is being displayed-- The whole point of separating the components in the first place.
Dec
12
awarded  Editor
Dec
12
comment Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
@Eric King thanks. I've updated the answer to be clearer.
Dec
12
revised Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
added 416 characters in body
Dec
12
comment Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
I believe this highlights a SoC issue that is prevalant in most PHP frameworks that don't correctly implement MVC. In MVC proper, controllers don't contain domain logic. Ideally the program flow would be: Controller gets $id, pulls the user from the repo then passes it into a model method for validation. This way the controller never has an knowledge of domain logic and the model is agnostic about where its domain entity comes from -it shouldn't have to come from the repository see blog.astrumfutura.com/2008/12/… for more info
Dec
12
comment Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
I have no idea why it was downvoted either, perhaps because it wasn't detailed enough. Anyway, I believe the issue, then, is a workaround for a limitation of your IoC container rather than a purely OO conceptual one. From a pure OOP perspective it's always best to inject the smallest, simplest level needed. In this instance, you're getting $user_id from somewhere. Use a User object instead of a scalar $user_id and this is a non-issue. It may present practical problems due to higher level architectural decisions but from a OO purist perspective this is the ideal methodology.
Dec
12
answered Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
Dec
11
comment OO PHP static keyword, should I use it?
Polymorphism not applying to static calls is precisely the problem. It locks client code into a VERY specific implementation this is inherently untestable because you're testing the static method at the same time as the client code.
Dec
11
comment OO PHP static keyword, should I use it?
The only time static calls do not introduce problems is when they're declared private and well documented for very specific reasons such as file-locking and connection throttling which are limited by external forces, however the original question was regarding general use-cases .
Dec
11
comment OO PHP static keyword, should I use it?
You should avoid static calls because they create unknown dependencies. This was my #1 point and for a reason: There's no avoiding this, it results in code which isn't portable and is tied to a very specific implementation. See: misko.hevery.com/2008/12/15/… for more information. All my points are valid and you haven't rebutted them at all. Tell me, why should static methods be used? You haven't explained this whereas my reasons for avoiding them are well documented.