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

Michael Feichtinger's Blog:
PHP5 WebSocket Example - A Simple Chat
Feb 03, 2011 @ 15:47:28

Michael Feichtinger has posted a simple websocket example to his blog today. It shows the creation of a simple "web chat" application for real-time communication without the mess that can come with ajax.

The classic example for websockets is a chat. This chat example has only 200 lines of code (excl. the Websocket class), is really easy to understand and customizable.

He creates a basic "WebsocketClass" class that (in his example) connects to an IP and port. It uses JSON as the messaging format and some basic javascript to handle the clicks of the "chat" and "login" buttons. You can see an example in action here and download the source for the server.php here.

tagged: websocket exmaple tutorial chat realtime json javascript

Link:

Wojciech Sznapka's Blog:
Accessing private object property from other object in PHP
Nov 16, 2010 @ 18:25:53

Wojciech Sznapka has a new post to his blog showing an interesting OOP programming strick related to accessing private properties in one object from another if they're derived from the same class.

Last time I wrote about Weirdest PHP construction I've ever seen, now I found another unusual PHP solution. PHP offers 3 visibility modifiers: private, protected and public. Private properties and methods can't be accessed outside the object, as well as from inherited classes. With one exception... They can be accessed by other instances of the same class. You can read more about it in the PHP manual.

In his code example he shows how to create two objects of the Foo class and, using getters and setters change the value of a private property from the first object on the second object.

tagged: private property object exmaple object

Link:


Trending Topics: