OOP Jargon

Skip to first unread message


Aug 21, 2007, 4:59:23 PM8/21/07
to Central Florida PHP

An excerpt from the Lavin OOP book that I'm not sure of the meaning...

class ThumbnailImage
//Data Members///////////
private $image;
private $quality = 100;
private $mimetype;
private $imageproperties = array();
private $initialfilesize;


--"The assignment of a value to $quality shows that data members may
be initialized upon declaration, but they must be initialized with
constant values. You could not, for instance, invoke a PHP function
call or a method"--

Huh? Upon declaration of ThumbnailImage, is that correct??

Does it mean I can do this?

$thumb = new ThumbnailImage();
$thumb ->quality = 80;

What would invoking a PHP function call or a method, which would not
be allowed, look like?

I hope I'm not setting anyone's IQ back by asking this. =p

Michael Girouard

Aug 21, 2007, 5:47:06 PM8/21/07
to cf...@googlegroups.com
No. Your code would still work just fine.

What this means is that when you define a class, you are allowed to automatically initialize the properties with values. So in his example, the $quality property is being initialize at a value of 100. Also $imageproperties is being initialized with an empty array.

Since these values don't require a function to be called, they are all legal.

It would be incorrect to say something like this:


class ThumbnailImage {

    private $filePath = dirname(__FILE__);



In my example, I add the $filePath property and attempt to initialize it with the current directory. Since a function call is being used to initialize the value of that property, it will throw a fatal error.

Reply all
Reply to author
0 new messages