 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
PHPMaster.com: Data Structures for PHP Devs Stacks and Queues
by Chris Cornutt June 18, 2013 @ 11:42:37
On PHPMaster.com today there's a new tutorial - the first part in a series - looking at data structures. In this first post Ignatius Teo looks at the concepts of "stacks" and "queues".
Most of us are familiar with "stacks" and "queues" in normal everyday usage. But, what do supermarket queues and vending machines have to do with data structures? Let's find out. In this article, I will introduce you to two basic abstract data types - the Stack and the Queue - which have their conceptual origins in everyday usage.
He introduces some of the common concepts behind these two ideas and includes some sample code showing how to implement them. He also mentions some of the SPL functionality that's bult into PHP to handle some of this. The SplStack and SplQueue objects take some of the hassle out of it for you.
voice your opinion now!
data structure stack queue tutorial splqueue splstack
Rob Allen: Objects in the model layer
by Chris Cornutt March 22, 2013 @ 10:45:54
In this latest post to his site Rob Allen talks some about application structure and the different kinds of objects he uses in his applications.
I currently use a very simple set of core objects within my model layer: entities, mappers and service objects. [...] I dislike the phrase "service object" as the word "service" means so many things to so many people. I haven't heard a better phrase yet that everyone understands though.
He defines each of the types of objects to help make the separation clearer. Here they are in brief:
- Entities are objects that represent something in my business logic.
- Mappers know how to save and load an entity from the data store.
- Service objects provide the API that the rest of the application uses.
Some of the comments on the post relate his choices to use in Zend Framework v2-based applications, noting that there are some base components you can extend to create these kinds of objects.
voice your opinion now!
object model entity mapper service oop structure znedframework2
Vinícius Krolow: Some tips to improve your codes readability
by Chris Cornutt January 25, 2013 @ 09:53:55
In this new post to his site Vinícius Krolow shares some tips he thinks will help to make your PHP code more readable in the long run.
What about code readability, from my point of view is one of the most important thing in the code. Who writes code that is easy to read, writes good code. Probably reading code is where you spent most part of your time, and not only your code, probably code of your team mates, or maybe code from the open source community, so write code that is simple and is easy to understand it's really important.
His tips (seven of them) are:
- Comment before write your code (DocBlock)
- Return frequently, Return early
- Break, Continue
- Code Standard / Name conventions
- Throw Exception
- Comment often, but not write stupid comments
- Methods can be always smaller than they are
It's a little difficult to read as the English isn't the speaker's native tongue, but it gets the point across. He also recommends reading this if you'd like more information about writing better OOP code that's easier to read.
voice your opinion now!
code readability recommendations structure comments conventions
Rob Allen: Thoughts on module directory structure
by Chris Cornutt January 04, 2013 @ 09:09:55
Rob Allen, in his Zend Framework 2 development, has come up with a list of suggestions about the use of modules in your applications, mainly relating to the structure of the files inside of them.
I've been working on a Zend Framework 2 module within a larger project that doesn't have that many PHP class files. Specifically, it has a controller, a mapper, an entity, a service and a form. As a result, the traditional Zend Framework 2 directory structure for the Account module looks [overly complicated]. That's a lot of directories for not many files! As a result, I decided to flatten it to [something simpler].
He includes both the "before" and "after" directory structures and continues on with two more suggestions - the removal of the top level "Account" folder inside of "src/" and, finally, removing "src/" all together with a slight modification to the autoloading. With a simpler module, though, something like this might make it easier to maintain and "follow" later down the road.
voice your opinion now!
zendframework2 module structure directory minimal
Josh Adell: Interfaces and Traits A Powerful Combo
by Chris Cornutt September 28, 2012 @ 08:51:16
Josh Adell has a new post today looking at the "powerful combination" of using traits and interfaces in PHP applications. He shows how, despite traits not implementing the interface directly, they can be used to make other classes adhere to them simply by "using" them.
If you're not using interfaces in PHP, you are missing out on a powerful object-oriented programming feature. An interface defines how to interact with a class. By defining an interface and then implementing it, you can guarantee a "contract" for consumers of a class. Interfaces can be used across unrelated classes. And they become even more useful when combined with the new traits feature in PHP 5.4.
He illustrates with a package shipping example and uses an "Addressable" Interface to define the structure for both a Company and Users class. He includes code showing how to implement it in a more traditional "implements" way in a class, but also shows an interesting way to achieve the same thing with traits. Having a trait that follows the interface makes it easy to have a class adhere to the interface just by including the trait (or "using" it).
voice your opinion now!
interface trait tutorial implement use structure
Danne Lundqvist's Blog: Getting to grips with an existing XML structure
by Chris Cornutt April 25, 2012 @ 10:44:43
Danne Lundqvist has a new post where he shares a bit of code he's written to "come to grips" with an existing XML structure.
Very often I find myself writing input filters for large XML files using PHP. Common enough task; and PHP offer a great variety of tools to do this effectively depending on the situation. Unfortunately, almost as common is the lack of documentation for the aforementioned XML files. [...] I have looked around for a simple tool but I didn't really find a tool that gave me the quick and dirty overview I wanted. A year or so ago I finally wrote a small PHP class to analyze large XML files.
He includes an example XML file, the HTML output of the parsing and a sample of how to use the class to parse and output the XML structure, complete with some CSS.
voice your opinion now!
xml structure schema parse output html csss
Sameer Borate's Blog: Building a Graph data structure in PHP
by Chris Cornutt February 15, 2012 @ 09:35:15
In the latest post to his blog Sameer Borate takes a look at using the Structures_Graph package from PEAR to create data structures in PHP with linked nodes for directed and undirected graphs.
The Pear Structures_Graph package allows creating and manipulating graph data structures. It allows building of either directed or undirected graphs, with data and metadata stored in nodes. The library provides functions for graph traversing as well as for characteristic extraction from the graph topology.
After sharing the one-line install, he shows how to create some instances of the package's Nodes and how to connect them to a graph and link them to other nodes. He includes a few examples - a simpler one with multiple nodes joined in a directed graph, another showing how to associate data with a node and how to query the graph for node connections and testing to see if the graph is acyclic.
voice your opinion now!
graph node structure structuregraph pear package tutorial
Larry Garfield's Blog: PHP project structure survey
by Chris Cornutt January 16, 2012 @ 13:08:38
Larry Garfield has posted the results of some of his research into popular PHP frameworks and projects and see how they handle their structure as it relates to the PSR-0 standard.
As Drupal is in the process of considering how to restructure code to best leverage the PSR-0 standard, I figured it would be wise to take a quick survey of how some other major projects organize their code bases. This is not a complete rundown of every project, simply roughly comparable notes for those areas Drupal is currently discussing. I am posting it here in the hopes that it will be useful to more than just Drupal.
The projects he looked to for his examples were:
voice your opinion now!
project structure survey namespace framework drupal
XpertDeveloper.com: Abstract in PHP
by Chris Cornutt October 28, 2011 @ 09:55:07
On the XpertDeveloper.com site today there's a new tutorial talking about something that can not only help the structure of your application but can make things more reusable in the end - abstract classes.
For Abstact keyword we can say that, abstract is type of the class and class which we can't create a object of it. Surprised???? [...] Abstract class can be used some what like an interface in PHP. So basically we can implement class using abstract. We can't extend more than one abstract class while we can implement more than one interface.
They introduce you to the creation of an abstract class and show how to set up some abstract methods inside. These methods are required to be defined as a part of the extension in your class. One of the benefits they don't mention of abstract classes over interfaces is the ability to have methods in the abstract that are actual code, not just definitions of the structure (that's more of what interfaces are for).
voice your opinion now!
abstract class structure interface code
|
Community Events
Don't see your event here? Let us know!
|