News Feed
Jobs Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Lukas Smith:
__toString() or not __toString()?
August 28, 2013 @ 09:14:39

In Lukas Smith's latest post he looks at one of the magic methods that's built into PHP to help transform objects into strings - the __toString method. In the post he explores what it's for and what it might be used for.

The __toString() belongs to the family of methods and functions called "magic functions". They are magic because for the most part they do not get called explicitly but rather intercept operations. Unfortunately there are limits to its magic, specifically the only "context" the method is aware of is its design contract: to return a string. But its not clear what purpose that is. Should this be for some internal debugging or logging purposes? There one would be most interested in internal identifiers and object state. Is it for some frontend UI where the user will most likely be interested in some textual identifier that isn't too long as to not clutter the UI. There in lies the dilemma in the magic, while useful there is no way to ensure that the given context is passed on.

He looks at use cases for UI output (for consistent output) and contexts as well as the more internal-facing usage, like for logging and debugging purposes. Being able to get the context of the object as a string and pushed into a log at the time of error could be immensely helpful for debugging. He also links to some discussions happening on Twitter about the internal versus external uses of this magic method.

0 comments voice your opinion now!
tostring magicmethod usecase internal external

Link: http://pooteeweet.org/blog/0/2231#m2231

Robert Basic's Blog:
A Zend Framework 2 EventManager use case
October 20, 2011 @ 11:05:43

Robert Basic has a new post to his blog today with an use case for Zend Framework 2's event manager to solve a problem he has with "repetitive code" in some of his models.

Basically, this allows us to have one piece of code to trigger an event and to have one or more listeners listening to this event. When the event gets triggered, the listeners are called and then we can do *something*, like caching or logging. Logging or caching. [...] See, that's my problem. All the event examples stop at logging and caching. Truly there must be some other example for which this event stuff can be used for.

In his example code, he's used the EventManager in one of his models to add listeners to validate the post and "slugify" the post's title for use on the URL. You can find his code on github if you're interested in the full implementation.

0 comments voice your opinion now!
zendframework eventmanager usecase model listener save


PHPMaster.com:
Documentation Makes the World Go Round
October 04, 2011 @ 09:03:16

On PHPMaster.com today there's a new article emphasizing something that lots of developers forget to make a part of their process when writing code - creating useful documentation to help make your code that much clearer.

If you're writing code that will be shared with others, put yourself in their shoes. Don't let your project lose potential users, community members, and possible contributors all because of insufficient documentation.

He (Matthew Turland) suggests a few things to keep in mind as you're writing up your documentation - the content is "king" (an emphasis on good descriptions/examples/use cases), open it up to external contributions using things like wikis (or even stored in the source code repository) and a focus on technical writing skills. Even the best tools out there can suffer if there's poor or no documentation.

0 comments voice your opinion now!
documentation application code opinion content usecase example technical writing


Timothy Boronczyk's Blog:
Currying in PHP
July 10, 2009 @ 13:33:18

Timothy Boronczyk has posted about an interesting concept you could use in your applications - currying (made possible in PHP 5.3.x and above):

What happens if you don't have all the arguments handy for a function, but you want to give whatever arguments you do have now and then provide the rest of them to the function later? This is called currying, and is a core concept in functional programming. It's messy, but possible to curry functions in PHP now that closures have been added.

He starts with an example from OCaml/F# to illustrate the point and moves to a PHP example - changing a normal function that requires three parameters into one that makes it possible to only submit the parameters you'd want to use. He also includes a more "real life" example of how it could be used in array filtering.

0 comments voice your opinion now!
usecase tutorial closures currying


Brian DeShong's Blog:
Development process for PHP-based projects
July 15, 2008 @ 15:11:25

Brian DeShong has posted some of his "food for thought" on the development process that's behind the scenes of different PHP applications.

Lately I've been doing a lot of thinking on development processes and quality, specifically for large-scale, professional PHP-based projects. [...] Generally speaking, my perception is that software development shops that really care about and emphasize quality have processes that consist of things such as writing use cases, unit testing and continuous integration.

He knows how he feels about all of this, be he wants to hear back from the community. How far does quality assurance go in your group? What kind of time/funding does this involve? Leave him a comment and let him know...

0 comments voice your opinion now!
development practice project unittest usecase review quality assurance



Community Events











Don't see your event here?
Let us know!


overview database introduction unittest security component hhvm application release hack language composer symfony2 opinion podcast install performance facebook package framework

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework