Re: functions classes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Larry,

I have hit similar global names space issues in the past and it is a pain in the behind!

One remedial method that can get it stable enough to start to work on is to stick the whole messy lot into classes (NOT OBJECTS!) and then the global name space becomes the local namespace (ie $MyVar becomes $GarbageCode::MyVar).

Once you have done this, you can put accessors functions around the class local variables. This means that all new code calls the accessors.

$newVar=GarbageCode::GetMyVar();

Thus, if you improve the internal representation of the garbage code, code outside the old garbage code will no longer be impacted by the change.

From an FN point of view, you are reducing the access to the variable to a single function point rather than many function points distributed throughout the code base.

Cheers

AJ

PS - if you knew all this before hand - please accept my apologies :-)

Larry Garfield wrote:
On Friday 25 August 2006 04:39, Bigmark wrote:
Can anyone tell me if it is relatively an easy process for an experienced
coder (not me) to convert a php script to mainly functions/classes.
I have my own script that i would like to make more streamlined as it is
becoming very difficult to work with.

That really depends on the nature of the code. I've some code I have to work with now that is built around dumping all kinds of stuff into the global namespace, even from functions. If I ever manage convince the author what an insanely bad idea that is, it will still be hell to fix because of the way it's built.

Most code probably isn't quite that bad, though. Your code could already break down into functions quite nicely, or it could be easier to just start from scratch. No way to tell without seeing the code.



--
www.deployview.com
www.nerds-central.com
www.project-network.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux