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

HHVM Blog:
Trait and interface requirements in Hack
Jun 19, 2015 @ 14:56:23

On the HHVM blog there's a recent post looking at some of the requirements around traits and interfaces in the Hack language. More specifically, they talk about type checking with traits and how interfaces can be used to help provide extra structure.

In PHP, traits are a mechanism of code reuse that, while very powerful, are also difficult to type check both efficiently and exhaustively. In this post we’ll dive more deeply into the reasons for that and see how Hack solves those problems, allowing you to use traits in a safe way without limiting their expressiveness.

They start by talking about the main problem with PHP's handling of traits (essentially copy and paste into the current class) and how they felt Hack should "just work" in allowing type checking on these "pasted" methods too. Performance limitations prevented them from handling it how they do with other variable types, so they changed things up, using a "require extends" syntax to tell the Hack engine how to allow the checking based on an interface. There's a lot more to it than this, so be sure to read the rest of the post on how they came to that conclusion.

tagged: trait interface requirement hack require extends syntax

Link: http://hhvm.com/blog/9581/trait-and-interface-requirements-in-hack

Pixelstech.com:
Should we use Abstract class or Interface?
Apr 18, 2013 @ 14:22:23

On the Pixelstech.com site today there's a new post that talks about the differences between abstract classes and interfaces and when's the best time to use either (or both).

When we write programs, we may often get into a situation where we don't know whether we should use Abstract class or Interface when we want to define an abstract object. These two are very similar and they are interchangeable. On Stackoverflow, this question is asked many times, it's related to many programming languages. Also in the official documentation of PHP regarding the Abstract class and Interface, people are arguing about this. To understand this question, we need to understand their differences and use scenarios.

They provide examples of abstract class and interface usage with one of the main differences being that you can define functionality in abstract classes. There's also examples showing classes that extend the abstract class while implementing the interface at the same time, helping to define the object structure to an even finer level.

tagged: abstract class interface tutorial choice extends implements

Link: http://www.pixelstech.net/article/1366044255_Should_we_use_Abstract_class_or_Interface_

WebReference.com:
Class Inheritance with PHP
Sep 12, 2007 @ 14:38:00

WebReference.com has a new tutorial posted today (from Kris Hadlock) concerning the class inheritance functionlaity that's a part of the object oriented structure in PHP:

There are many benefits of inheritance with PHP, the most common is simplifying and reducing instances of redundant code. Class inheritance may sound complicated, but think of it this way. Consider a tree. A tree is made up of many parts, such as the roots that reside in the ground, the trunk, bark, branches, leaves, etc. Essentially inheritance is a connection between a child and its parent. [...] This article assumes a basic understanding of OOP with PHP.

They show how to create the parent object as a base and how to inherit it into a child class - using the extend keyword in the class definition. They give an example of their sample code in action so you can see how the inheritance is handled.

tagged: class object oriented inheritance parent extends tutorial class object oriented inheritance parent extends tutorial

Link:

WebReference.com:
Class Inheritance with PHP
Sep 12, 2007 @ 14:38:00

WebReference.com has a new tutorial posted today (from Kris Hadlock) concerning the class inheritance functionlaity that's a part of the object oriented structure in PHP:

There are many benefits of inheritance with PHP, the most common is simplifying and reducing instances of redundant code. Class inheritance may sound complicated, but think of it this way. Consider a tree. A tree is made up of many parts, such as the roots that reside in the ground, the trunk, bark, branches, leaves, etc. Essentially inheritance is a connection between a child and its parent. [...] This article assumes a basic understanding of OOP with PHP.

They show how to create the parent object as a base and how to inherit it into a child class - using the extend keyword in the class definition. They give an example of their sample code in action so you can see how the inheritance is handled.

tagged: class object oriented inheritance parent extends tutorial class object oriented inheritance parent extends tutorial

Link:

CodeSnipers.com:
Embarking on PHP5 Objects
Jan 18, 2006 @ 12:40:42

From CodeSnipers.com today, there's a new post with their look at objects in PHP5 - how they work, how they're different from in PHP4, and some code to show their use.

After a brief few weeks studying Perl and its nuances I'm going to take a look at PHP5 Objects.

One of the annoying things with object in PHP 4 was you had to use a lot of references, you know, that funny & symbol. No longer needed in PHP 5 because you use "Object Handles" perhaps similar to a file handler you when fopen a file. Also available now are access modifiers "public/protected/package" and interface implementation. I can hear the beer mugs of java programmers being raised in celebration to this one. Also new to PHP 5 are real constructors and destroy methods. There are many more features, but lets see some code.

There are code examples that show some of the new keywords (private, public, etc) that the object structure uses, as well as how you can use them. They link to the PDF of Power PHP 5 Programming for a good place to start...

tagged: php5 object class public private implements extends php5 object class public private implements extends

Link:

CodeSnipers.com:
Embarking on PHP5 Objects
Jan 18, 2006 @ 12:40:42

From CodeSnipers.com today, there's a new post with their look at objects in PHP5 - how they work, how they're different from in PHP4, and some code to show their use.

After a brief few weeks studying Perl and its nuances I'm going to take a look at PHP5 Objects.

One of the annoying things with object in PHP 4 was you had to use a lot of references, you know, that funny & symbol. No longer needed in PHP 5 because you use "Object Handles" perhaps similar to a file handler you when fopen a file. Also available now are access modifiers "public/protected/package" and interface implementation. I can hear the beer mugs of java programmers being raised in celebration to this one. Also new to PHP 5 are real constructors and destroy methods. There are many more features, but lets see some code.

There are code examples that show some of the new keywords (private, public, etc) that the object structure uses, as well as how you can use them. They link to the PDF of Power PHP 5 Programming for a good place to start...

tagged: php5 object class public private implements extends php5 object class public private implements extends

Link:


Trending Topics: