NYCPHP Meetup

NYPHP.org

[nycphp-talk] nyc php classes (night/long format)

Rob Marscher rmarscher at beaffinitive.com
Thu Jun 14 00:22:18 EDT 2007


Hey David,

A couple quick things I thought I'd point out:

On Jun 13, 2007, at 11:09 AM, David Krings wrote:
> Unlike objects, I have no idea what classes can do and are there  
> for, although I haven't really used either (I used a few objects,  
> such as the zip object).

Classes are actually the way that you define objects.  So they're  
really the same thing and you'll often see the terms used  
interchangeably.  So somewhere out there (in this case, probably  
written in C and compiled into the zip extension), there is a class  
that defines the zip objects you've been using.  Here's a quick example:

class ZipArchive
{
   protected $file;

   public function open($filename)
   {
     echo "code to handle reading $file would go here";
     return true;
   }

   // etc...
}

So that's the class... but as soon as you do this:

$zip = new ZipArchive();
$zip->open('somefile.zip');

$zip is an object.  Does that make sense?  I'm sure the books will  
lay it all out, but just thought I'd clarify the class vs. object thing.

On Jun 13, 2007, at 1:34 PM, David Krings wrote:
> I am more interested in improving the maintainability of my code. I  
> often do not anticipate what I might want to do and when I add  
> functionality I often find myself creating code that is only  
> slightly different from existing code. I sometimes manage to  
> simplify and externalize into functions that can be included when  
> needed, but something tells me that there might be a better way.

This process of simplifying and combining code to be reusable is  
called "refactoring" and it's one of the best skills a developer can  
possess.  Googling "refactoring php" will bring up a few articles.  I  
also saw that the June 2006 issue of php|a has an article on  
refactoring your procedural code (functions) into object-oriented  
code (classes/objects).  I haven't read it though so I can't comment  
on how good it is or easy to understand but here's a link to get it:  
http://www.phparch.com/issue.php?mid=82


Later,
Rob







More information about the talk mailing list