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

Mathias Verraes:
Objects as Contracts for Behaviour
Sep 29, 2014 @ 16:10:33

Mathias Verraes has a new post to his site today with an interesting idea when it comes to handling the architecture of an application: using objects as the contracts for behavior. He suggests that the objects themselves define how other pieces of code should interact with them, not necessarily external services. He illustrates with an invoice and appointment example.

Of course invoices do not pay themselves, but that’s not what an object model is trying to do. An invoice exposes the behaviour of being able to be paid. That ability is in fact essential to what it means to be an invoice. The behaviour is an inherent property of an invoice. If an invoice doesn’t have the ability of being paid, there’s no point in issuing invoices at all. In other words, the contract of an invoice object declares that its interface includes payment as a feature. Its promise to the outside world is that it allows an outsider to pay for it. Encapsulation of state and behaviour is the core idea behind objects.

He wonders why, if this is more true to the "object-oriented programming" ideals, the idea of encapsulating procedural code as objects is so widespread. He suggests a lack of education on the subject or maybe even confusion from spoken languages themselves.

tagged: objectoriented programming oop contract expose behavior property

Link: http://verraes.net/2014/09/objects-as-contracts-for-behaviour/

SitePoint PHP Blog:
How to Expose PHP's Private Parts
Nov 11, 2008 @ 15:32:14

On the SitePoint PHP Blog Troels Knak-Nielsen has worked up a way to "expose PHP's private parts" when it comes to finding out more about the object/variable he's working with (without a usual print_r or var_dump).

I've been tinkering with dumping PHP objects, and have found myself constantly running into a brick wall. The output from print_r and friends is fine in some contexts, but for larger structures, it would be nice to tidy the output up a bit and wrap it in some HTML.

His solution is to serialize the object into a string (keeping all related meta information) that can be passed around and parsed back into its original form for debugging. He's included the script that works bye taking in the string and manually parsing it back out into its parts into a useful array.

tagged: expose output debug serialize object private protected tutorial

Link:

International PHP Magazine:
Which of the Following Ensures Smooth Implementation of PHP Sessions?
May 03, 2007 @ 16:14:00

The results from the latest poll the International PHP Magazine conducted this past week are in. The question they asked developers to respond to was "Which One of the Following Ensures Smooth Implementation of PHP Sessions?".

Options this time were:

  • Don't use underscore in host names
  • Commit your session before it redirects
  • Prevent session fixation
  • Don't expose session_id's
The results were pretty close for all of the options with one coming out on top (committing the session) and two tying for second - preventing session fixation and not exposing session IDs.

Subversion and Symfony users should cast their votes in this week's poll. It asks, of the four options given, which is your favorite "trick" to running the Symfony framework with Subversion.

tagged: pol session implementation commit fixation expose subversion symfony pol session implementation commit fixation expose subversion symfony

Link:

International PHP Magazine:
Which of the Following Ensures Smooth Implementation of PHP Sessions?
May 03, 2007 @ 16:14:00

The results from the latest poll the International PHP Magazine conducted this past week are in. The question they asked developers to respond to was "Which One of the Following Ensures Smooth Implementation of PHP Sessions?".

Options this time were:

  • Don't use underscore in host names
  • Commit your session before it redirects
  • Prevent session fixation
  • Don't expose session_id's
The results were pretty close for all of the options with one coming out on top (committing the session) and two tying for second - preventing session fixation and not exposing session IDs.

Subversion and Symfony users should cast their votes in this week's poll. It asks, of the four options given, which is your favorite "trick" to running the Symfony framework with Subversion.

tagged: pol session implementation commit fixation expose subversion symfony pol session implementation commit fixation expose subversion symfony

Link:

Oscar Merida's Blog:
Avoiding frustration with PHP Sessions
Mar 30, 2007 @ 16:28:00

On his blog, Oscar Merida has a quick new post those just starting out with sessions should take a look at. He gives four quick tips of things to watch out for that can help your development process go smoother.

PHP's support for sessions make adding "state" to your web application super easy. Bus because the illusion of state is maintained by storing a Session ID via a user's cookies, you might find yourself losing potentially productive hours chasing down bizarre client side bugs or opening up a potential security hole. Here are 4 tips to help you avoid wasting your time and securing your site.

Items on the list are:

  • Don't use underscores in host names
  • Commit your sessions before redirects
  • Prevent session fixation (great security tip!)
  • Don't expose session_id's
Check out the comments - there's some good recommendations in there as well.

tagged: frustration session avoid recommend underscore fixation expose frustration session avoid recommend underscore fixation expose

Link:

Oscar Merida's Blog:
Avoiding frustration with PHP Sessions
Mar 30, 2007 @ 16:28:00

On his blog, Oscar Merida has a quick new post those just starting out with sessions should take a look at. He gives four quick tips of things to watch out for that can help your development process go smoother.

PHP's support for sessions make adding "state" to your web application super easy. Bus because the illusion of state is maintained by storing a Session ID via a user's cookies, you might find yourself losing potentially productive hours chasing down bizarre client side bugs or opening up a potential security hole. Here are 4 tips to help you avoid wasting your time and securing your site.

Items on the list are:

  • Don't use underscores in host names
  • Commit your sessions before redirects
  • Prevent session fixation (great security tip!)
  • Don't expose session_id's
Check out the comments - there's some good recommendations in there as well.

tagged: frustration session avoid recommend underscore fixation expose frustration session avoid recommend underscore fixation expose

Link:


Trending Topics: