[thelist] personal PHP preference inquiry

Jonathan Dillon jdillon at boehm-ritter.com
Tue Apr 26 15:41:54 CDT 2005


 
-----Original Message-----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org] On Behalf Of Antonio Angelo
Sent: Tuesday, April 26, 2005 11:01 AM
To: Rick den Haan; thelist at lists.evolt.org
Subject: Re: [thelist] personal PHP preference inquiry

2005/4/24, Rick den Haan <rick.denhaan at gmail.com>:
> I was wondering how all you PHP programmers out there work with custom 
> functions. Do you like to:
> 
> a) put all necessary functions in the page itself;
> b) put all functions in one seperate file, and include this big file 
> into the page;
> c) put each function in its own file, and include when needed;
> d) else?

Abandon all hope, and stop programming in proceedural php.  It's VERY easy
to simply put your code into a class file.  I always have a directory called
/classes in the doc root.  If you make a class called example, for example,
you would do:

/classes/example_class.php (or something similar).

Working with classes is CAKE.

A class looks like this in php4:

<?
class example {

	// sample var
	var $myvar;

	// init method (a method is function in a class) for constructor
	function example() {
		// stick my default variable(s) here
	}

	function getExample() {
		SQL here...
	}
}
?>

To access this in a page is SO easy...

<?
include("/classes/example_class.php");
$example = new example;

echo $example->myvar;
?>

Sorry, I thought I should take the opportunity to throw out some OO php.
I've been working with it now for the last few years, and it's fantastically
easier.

J



More information about the thelist mailing list