[PHP] Re: PHP 4 OOP, re-using a object?

2006-09-10 Thread M. Sokolewicz

Micky Hulse wrote:

Hi,

I am slowly learning how to use classes properly... quick question:

# Create the object:
$doSplash = new RandomSplash(); // Create the object.

Shouldn't I be able to call that object like below, throughout my page:

...HTML...
?php $doSplash-randomize('css'); ?
...HTML...
?php $doSplash-randomize('xhtml top'); ?
...HTML...
?php $doSplash-randomize('xhtml bot'); ?
...HTML...

Sorry, this is probably a noob question... I am pretty good at using 
functions, but classes are still new to me.


Any help, even a RTFM link, would be really appreciated. :)

Have a great day!
Cheers,
Micky


you should be able to, and it works fine for me. www.php.net/oop will 
help, if you haven't read it.


- tul

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



[PHP] Re: [PHP-DB] OOP vs Functions and includes

2004-11-16 Thread Bruno B B Magalhães
Pablo,
This is a very complex discussion... But generalizing, a LOT, OO is  
more appropriated for big systems due to its extensibility and easy  
maintenance, while procedural approach works best for small  
applications that don't require to much updates and aren't too complex.

Here is a example of a controller of my framework, can you imagine it  
using procedural approach?  
(http://www.yourhostname.com/controller/articles)

?php
/**
* Project: BBBM Framework
* File: site
*
* @desc Site Controller
* @link http://www.bbbm.com.br/
* @copyright 2004 Bruno B B Magalhaes
* @author Bruno B B Magalhaes [EMAIL PROTECTED]
* @package BBBM Framework
* @version 0.7-dev
*/
define('FRAMEWORK_DIR',dirname(__FILE__).'/framework/');
require_once(FRAMEWORK_DIR.'framework.inc.php');
/**
* Starting Framework
*/
$framework = new framework();
/**
* Checking if it's a valid and installed Controller
*/
if(isset($framework-input-uri['1']))
{
	$framework-benchmark-mark('framework','loading_called_controller');
	if(!$framework-load_controller($framework-input-uri['1']))
	{
		echo '[FRAMEWORK FATAL ERROR] There are no registered or active  
controllers!';
		exit;
	}
}
else
{
	$framework-benchmark-mark('framework','loading_default_controller');
	if(!$framework-load_controller())
	{
		echo '[FRAMEWORK FATAL ERROR] There are no registered or active  
controllers!';
		exit;
	}
}

/**
* Getting all modules from this controller and module information from  
database
*/
$framework-benchmark-mark('framework','loading_controller_modules');
$framework-modules-get_modules($framework- 
controller['controllerPath']);

/**
* Configuring Output (Templates dirs, Compile dirs, etc)
*/
$framework-benchmark-mark('framework','configuring_controller');
$framework-output-configure_controller($framework- 
controller['controllerPath']);

/**
* If a controller needs authentication, try to authenticate!
*/
$framework-benchmark-mark('framework','authenticating_controller');
$framework-authentication-authenticate($framework- 
controller['controllerPath'],$framework- 
controller['controllerLevel']);
if(!$framework-authentication-authenticated)
{
	if(isset($framework-authentication-errormsg))
	{
		$framework-output-assign('errormsg',$framework-authentication- 
errormsg);
	}
	$framework-output-display($framework- 
controller['controllerPath'].'.templates/login.tpl',session_id());
	$framework-benchmark-stop('framework');
	exit;
}
	
/**
* Getting Module Information, if exists, else get the default module  
for this controller
*/
if(isset($framework-input-uri['2']))
{
	$framework-benchmark-mark('framework','loading_called_module');
	$framework-modules-get_module($framework-input-uri['2']);
}
else
{
	$framework-benchmark-mark('framework','loading_default_module');
	$framework-modules-get_module();
}

/**
* Starting module initialization routines
*/
$framework-benchmark-mark('framework','initializing_module');
if(isset($framework-modules-module)  $framework-modules-module !=  
''  $framework-modules-module != false   
is_array($framework-modules-module))
{
	/**
	* If a module needs authentication, try to authenticate!
	*/
	$framework-benchmark-mark('framework','authenticating_module');
	if($framework-controller['controllerLevel']   
$framework-modules-module['moduleLevel'])
	{
		$framework-authentication-authenticate($framework-modules- 
module['modulePath'],$framework-modules-module['moduleLevel']);
		if(!$framework-authentication-authenticated)
		{
			if(isset($framework-authentication-errormsg))
			{
$framework-output-assign('errormsg',$framework-authentication- 
errormsg);
			}
			$framework-output-display($framework- 
controller['controllerPath'].'.templates/login.tpl',session_id());
			$framework-benchmark-stop('framework');
		}
	}
	
	/**
	* Checking if the called module is an alias, and if the alias exists  
and exits after it!
	*/
	$framework-benchmark- 
mark('framework','checking_and_loading_alias_module');
	if($framework-modules-module['moduleType'] == 'alias')
	{
		if(isset($framework-modules-module['moduleAliasPath'])   
$framework-modules-module['moduleAliasPath'] != ''   
file_exists(FRAMEWORK_DIR.$framework- 
controller['controllerPath'].'.aliases/'.$framework-modules- 
module['moduleAliasPath'].'.func.php'))
		{
			include_once(FRAMEWORK_DIR.$framework- 
controller['controllerPath'].'.aliases/'.$framework-modules- 
module['moduleAliasPath'].'.func.php');
		}
		elseif(isset($framework-modules-module['modulePath'])   
$framework-modules-module['modulePath'] != ''   
file_exists(FRAMEWORK_DIR.$framework- 
controller['controllerPath'].'.aliases/'.$framework-modules- 
module['modulePath'].'.func.php'))
		{
			include_once(FRAMEWORK_DIR.$framework- 
controller['controllerPath'].'.aliases/'.$framework-modules- 
module['modulePath'].'.func.php');
		}
		else
		{
			echo '[MODULE INITIALIZATION] No module to load!';
		}
		exit;
	}
	
	/**
	* Including module
	*/
	$framework-benchmark-mark('framework','including_module');
	

[PHP] Re: [PHP-DB] OOP vs Functions and includes]

2004-11-16 Thread Jonel Rienton

 Original Message 
Subject: Re: [PHP-DB] OOP vs Functions and includes
From: Jonel Rienton [EMAIL PROTECTED]
Date: Tue, November 16, 2004 7:04 pm
To: [EMAIL PROTECTED]

Hi again Pablo,

not sure how the inner workings of PHP are as far as instantiating new
classes. other languages i've used only (jit-)compile methods/member
functions as they are called thus reducing the amount of memory in
instantiating objects.

regards,
Jonel

 Thanks for your response Jonel.
 I mistakenly posted this in the PHP-DB list, I wanted to do it in the
 General list instead.
 Anyway, I heard those words you mention in several OOP introduction
 sites   but I guess never understood it.
 I'll try to re-read that focsing in them.

 One question tho, I saw classes use functions within them... dont they
 require more memory on the server side ?
 Thanks !

 Pablo.



 On Tue, 16 Nov 2004 18:40:51 -0600 (CST), Jonel Rienton
 [EMAIL PROTECTED]   wrote:

 Hi Pablo,

 The 3 main strong points of using OOP are:

 1. Encapsulation
 2. Inheritance
 3. Polymorphism

 I like using OOP instead of includes because of these points.  It
 helps   me
 alot in doing maintenance releases using this technique instead of
 having to deal with thousands of codes which can be abstracted from
 me with encapsulation for instance.

 regards,
 Jonel

 Hi, This is my first post. English is my 2nd language so I apologize
 for
   any mistakes I might have.

 I would describe myself as an intermediate self-thaught PHP
 programmer,
  which means I can do lots of stuff but probly my coding techniques
 sucks :P

 Anyway, Im reading a lot about OOP lately, and I've fixing other's
 people   scripts which use OOP for small stuff that could have
 been acomplished   with simple functions or includes maybe... so I
 started wondering, why use   OOP when you can use something
 simpler...

 Imagine the following example:
 A table of MySQL on a simple classifieds site holds the info for
 each Ad
   posted ( timestamp, user who posted it, title, description,
 location,
  country, etc).
 A php page called ads.php gets the ad ID via $_GET and prints out
 its information in a nicely formated page.

 What I usually do is to put all the echo-ing part of this page in
 a separate include (ie: ads_details.php ), so that if I need to also
 show
  this in another page, I call the same include.  If I decide to do a
 change   later, I only have to change it in one part of the script
 alone.

 What I've seen a lot lately is that people do the same with classes
 (they   write a class that will output the same thing I output thru
 an include)...   so I guess there must be  pros and cons regarding
 using both methods...

 Could anyone point me to a good reading (free, internet) material to
 read   about this or any other advice so I continue learning about
 OOP and when   to use it ?

 If you read it all the way down here THANKS !  :D

 Pablo Fernandez-Stearns
 BA. Argentina.

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





 --
 Using Opera's revolutionary e-mail client: http://www.opera.com/m2/


-- 


-- 

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



[PHP] Re: PHP 5/OOP, Functionality similar to an Abstract method?

2004-06-12 Thread Justin Patrin
Chris wrote:
I have an abstract class with quite a few 'children'. Essentially I want 
to be able to interchange calls between children (Take a script, written 
with ClassA and redefine the variable as ClassB etc.)

Though there is a large subset of methods all of these children declare, 
there are a few which only *some* declare. What I think I'm looking for 
is a variation on an abstract method that, if not defined in a child, 
will do nothing. Using an abstract method forces me to declare the 
method in the child with an empty body.

AFAIK, there is no support for this explicitly in PHP5. You would have 
to implement something yourself, like putting a die() or exit in the 
abstract method in the parent class.

If you just want an empty funciton anyway, why don't you just put an 
empty function in the parent? I don't see why you would need PHP to yell 
at you when you don't want to do antyhing with it anyway.

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


Re: [PHP] Re: PHP 5/OOP, Functionality similar to an Abstract method?

2004-06-12 Thread Chris
Justin Patrin wrote:
Chris wrote:
I have an abstract class with quite a few 'children'. Essentially I 
want to be able to interchange calls between children (Take a script, 
written with ClassA and redefine the variable as ClassB etc.)

Though there is a large subset of methods all of these children 
declare, there are a few which only *some* declare. What I think I'm 
looking for is a variation on an abstract method that, if not defined 
in a child, will do nothing. Using an abstract method forces me to 
declare the method in the child with an empty body.

AFAIK, there is no support for this explicitly in PHP5. You would have 
to implement something yourself, like putting a die() or exit in the 
abstract method in the parent class.

If you just want an empty funciton anyway, why don't you just put an 
empty function in the parent? I don't see why you would need PHP to 
yell at you when you don't want to do antyhing with it anyway.

When I said will do nothing I was meaning the method call, not the 
entire script. I can't put anything into an abstract method, it only 
defines the method name and argument list, a body is nto allowed in an 
abstract method.

Upon further reflection it appears that the abstract method is what I 
really want. I'll just have to implement an empty body.

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


[PHP] Re:[PHP] dreading OOP

2003-01-21 Thread Sukrit
 Larry == Larry Brown [EMAIL PROTECTED] writes:

Larry places.  However, my mind apparently works different and I
Larry keep trying to relate the OOP structure to what I already
Larry know which equates an object to a function.  I am resolving

This happens a lot with me too :) 

Larry to purchase a book dedicated to instruction in the inns and
Larry outs of OOP.  Specifically at it relates to PHP would be
Larry great but my emphasis is towards something that teaches
Larry someone that is stubborn in his reliance on previously
Larry learned methods.  I hope this makes sense and I'm not alone
Larry on this. :) Any suggestions would be greatly appreciated!

i am having a hard time with OOP too. i did buy a book Object Oriented
Analysis and Design Andrew Haigh. Well, it doesn't have PHP but it's
otherwise very lucid and clear. It also covers UML. Haven't read much
of it till now but i think it might help you.

Learning to think in terms of object is really diffucult imho, for
someone who is still stuck in the older procedural paradigm like
us. It'll take time. 

Wishing us all OO enlightenment :)
regards
sukrit


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




RE: [PHP] Re:[PHP] dreading OOP

2003-01-21 Thread Larry Brown
Thank you, I'll check this book out.

Larry S. Brown
Dimension Networks, Inc.
(727) 723-8388

-Original Message-
From: Sukrit [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 21, 2003 12:39 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Re:[PHP] dreading OOP

 Larry == Larry Brown [EMAIL PROTECTED] writes:

Larry places.  However, my mind apparently works different and I
Larry keep trying to relate the OOP structure to what I already
Larry know which equates an object to a function.  I am resolving

This happens a lot with me too :)

Larry to purchase a book dedicated to instruction in the inns and
Larry outs of OOP.  Specifically at it relates to PHP would be
Larry great but my emphasis is towards something that teaches
Larry someone that is stubborn in his reliance on previously
Larry learned methods.  I hope this makes sense and I'm not alone
Larry on this. :) Any suggestions would be greatly appreciated!

i am having a hard time with OOP too. i did buy a book Object Oriented
Analysis and Design Andrew Haigh. Well, it doesn't have PHP but it's
otherwise very lucid and clear. It also covers UML. Haven't read much
of it till now but i think it might help you.

Learning to think in terms of object is really diffucult imho, for
someone who is still stuck in the older procedural paradigm like
us. It'll take time.

Wishing us all OO enlightenment :)
regards
sukrit


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



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




[PHP] Re: PHP and OOP

2002-06-27 Thread Jesper Brunholm

[EMAIL PROTECTED] wrote:
 i want to build a site in fully OO style but that will
 significantly slow down execution time 

Do you have any documentation on this? - I'm getting quite used to read 
and hear the very opposite.

Previously programmers even argued that asp was faster than php because 
it was more OO.

Regards

Jesper Brunholm

-- 
Phønix - Danish folk music from young musicians - http://www.phonixfolk.dk



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




[PHP] Re: PHP and OOP

2002-06-27 Thread Kondwani Spike Mkandawire

I still don't get what the big fuss of OO programming is about
I do agree that it is stylistic hence helps someone else who
hasn't written your code to follow up on what you are doing...
But so far the programs I have been writing in OO supported
languages have been written and scripted on an as is needed
basis...  i.e.  I have the basic idea then I simply start scratching
down methods/functions I have never sat down and drawn
a single UML diagram on a project that I am about to do...

How many of us have done so?  Could some one please
point out another feasible advantage of OO programming
a part from the fact that I would make someone else's work
easier by using this style of programming...

Spike...
Jesper Brunholm [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 [EMAIL PROTECTED] wrote:
  i want to build a site in fully OO style but that will
  significantly slow down execution time

 Do you have any documentation on this? - I'm getting quite used to read
 and hear the very opposite.

 Previously programmers even argued that asp was faster than php because
 it was more OO.

 Regards

 Jesper Brunholm

 --
 Phønix - Danish folk music from young musicians - http://www.phonixfolk.dk





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




RE: [PHP] Re: PHP and OOP

2002-06-27 Thread Jay Blanchard

[snip]
I still don't get what the big fuss of OO programming is about ...How many
of us have done so?  Could some one please point out another feasible
advantage of OO programming a part from the fact that I would make someone
else's work easier by using this style of programming...
[/snip]

It's not just about style, as a matter of fact it has nothing to do with
style at all. I guess this comes from mostly other programming venues...

OOP is a method of making code more modular, containerizing things which
logically belong togther by group. You can create special instances of the
group, but you don't have to keep them if you don't need them. It also has
the benefit of making code more reusable. I can create classes for things
that I can use over and over again in various applications. As a matter of
fact, I have a 'customer' class that I use in every application within the
company. If the customer changes I can modify the class without breaking
existing code. If I have a special customer I can create an instance of that
customer reflecting special qualities not found in the customer class, and
then discard that instance once it is no longer needed. In order to have
that special customer I only have to add the special characteristics and
inherit everything else from the standard customer class.

Since scripting languages, like PHP, PERL, VBScript and others have
traditionally (up until a couple of years ago) been top down languages,
OOP has not caught on as quickly amongst web development enthusiasts. The
folks at PHP readily admit that there are some things lacking in their OO
implementation, and no matter what happens you have to use those classes
with non-object procedures. And that is the same for every so-called OO
language.

An example that gets used a lot is the vehicle class. Think of all the
different types of vehicles out there
*cars   *helicopters
*trucks *boats
*bicycles   *hovercraft
*buses  *motorcycles
*airplanes  *scooters

now think about the instances of cars (sub classes, if you will)
*sedan  *sports car
*town car   *limosine

and think about all the brands a car can be
*BMW*Ford
*Toyota *Chevrolet
*Audi   *Mini-Cooper

and think about the characteristics
*four door  *two door
*hatchback

Of course the above is a very incomplete example. But you can see where
having a base class could help. Then other classes that inherit from the
classes above that, and so on.

The bottom line on OOP in PHP though? Use it where and when it makes sense.
It is not right for every application or situation. But if you find yourself
using something over and over again that is not a function (like a database
connection scheme, I have that in a function which is included() when
needed. I pass variables to it for all the required info) but rather
describes an object or class of objects, you may want to set up a class.

HTH!

Jay



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




RE: [PHP] Re: PHP and OOP

2002-06-27 Thread SP

OO is slower then procedural.  You can test that out yourself or look at
this article where the guy did a very basic test.  Maybe they will fix the
speed problem by the time php5 comes around.
http://www.phpbeginner.com/columns/demitrious/objects/8



-Original Message-
From: Kondwani Spike Mkandawire [mailto:[EMAIL PROTECTED]]
Sent: June 27, 2002 8:10 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Re: PHP and OOP


I still don't get what the big fuss of OO programming is about
I do agree that it is stylistic hence helps someone else who
hasn't written your code to follow up on what you are doing...
But so far the programs I have been writing in OO supported
languages have been written and scripted on an as is needed
basis...  i.e.  I have the basic idea then I simply start scratching
down methods/functions I have never sat down and drawn
a single UML diagram on a project that I am about to do...

How many of us have done so?  Could some one please
point out another feasible advantage of OO programming
a part from the fact that I would make someone else's work
easier by using this style of programming...

Spike...
Jesper Brunholm [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 [EMAIL PROTECTED] wrote:
  i want to build a site in fully OO style but that will
  significantly slow down execution time

 Do you have any documentation on this? - I'm getting quite used to read
 and hear the very opposite.

 Previously programmers even argued that asp was faster than php because
 it was more OO.

 Regards

 Jesper Brunholm

 --
 Phønix - Danish folk music from young musicians - http://www.phonixfolk.dk





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




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




Re: [PHP] Re: PHP and OOP

2002-06-27 Thread Erik Price


On Thursday, June 27, 2002, at 08:10  AM, Kondwani Spike Mkandawire 
wrote:

 I still don't get what the big fuss of OO programming is about
 I do agree that it is stylistic hence helps someone else who
 hasn't written your code to follow up on what you are doing...
 But so far the programs I have been writing in OO supported
 languages have been written and scripted on an as is needed
 basis...  i.e.  I have the basic idea then I simply start scratching
 down methods/functions I have never sat down and drawn
 a single UML diagram on a project that I am about to do...

 How many of us have done so?  Could some one please
 point out another feasible advantage of OO programming
 a part from the fact that I would make someone else's work
 easier by using this style of programming...

I never used UML for the project I'm working on (and am almost finished 
with), but I sure wish that I had.  I just didn't know UML or even OO 
programming when I started.  Basically I started out writing a giant 
application with procedural code, and then as I learned how to use 
objects, I cleaned everything up by using objects to represent most of 
the actors and data.  But because I never properly modeled my project 
(my fault I know, I'm not blaming anyone else but me), it is far uglier 
than I would like.

This assignment is almost done, but I have been learning Java in my free 
time and it is my plan to properly model this project and rewrite it in 
Java as an exercise.  Maybe not implement every single detail, but get 
the bulk of it.

Life is one big learning exercise anyway



Erik







Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Re: PHP and OOP

2002-06-27 Thread Remy Dufour

I've tested thecode and there is what i've got
Proceduraltook 1.24408602715 seconds
OOtook 1.24240803719 seconds
Here is the code. Test it by yourself
?phpfunction getmicrotime(){list($usec, $sec) = explode(
,microtime());return ((float)$usec + (float)$sec);}function
icount($vs) {$var=0;while($count  $vs) {
$count++;}}$time_start = getmicrotime();icount(100);
echo Proceduralbr took . (getmicrotime() - $time_start) . secondsbr;
class count {function icount($vs) {$var=0;
while($count  $vs) {$count++;}}}
$time_start = getmicrotime();$icount = new count;
$icount-icount(100);echo brOObr took . (getmicrotime() -
$time_start) . seconds;?

 OO is slower then procedural.  You can test that out yourself or look at
 this article where the guy did a very basic test.  Maybe they will fix the
 speed problem by the time php5 comes around.
 http://www.phpbeginner.com/columns/demitrious/objects/8



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




Re: [PHP] Re: PHP and OOP

2002-06-27 Thread B i g D o g

You also need to remember that these tests need to be run 100s of times and
then calculate the avg.  However, as we can assume there is really not going
to be a big difference between the two.  Its not like they are whole seconds
apart.


B i g D o g


- Original Message -
From: Remy Dufour [EMAIL PROTECTED]
To: SP [EMAIL PROTECTED]; Kondwani Spike Mkandawire
[EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Thursday, June 27, 2002 11:34 AM
Subject: Re: [PHP] Re: PHP and OOP


 I've tested thecode and there is what i've got
 Proceduraltook 1.24408602715 seconds
 OOtook 1.24240803719 seconds
 Here is the code. Test it by yourself
 ?phpfunction getmicrotime(){list($usec, $sec) = explode(
 ,microtime());return ((float)$usec + (float)$sec);}
function
 icount($vs) {$var=0;while($count  $vs) {
 $count++;}}$time_start = getmicrotime();
icount(100);
 echo Proceduralbr took . (getmicrotime() - $time_start) .
secondsbr;
 class count {function icount($vs) {$var=0;
 while($count  $vs) {$count++;}}}
 $time_start = getmicrotime();$icount = new count;
 $icount-icount(100);echo brOObr took . (getmicrotime() -
 $time_start) . seconds;?

  OO is slower then procedural.  You can test that out yourself or look at
  this article where the guy did a very basic test.  Maybe they will fix
the
  speed problem by the time php5 comes around.
  http://www.phpbeginner.com/columns/demitrious/objects/8



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


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




RE: [PHP] Re: PHP and OOP

2002-06-27 Thread SP

Never tested it so I tried it out for the fun of it.  I didn't use yours but
I used the other guy's code on separate pages and did it ten times.  I guess
I was wrong, I got around 2% difference.  Definitely not the 20% difference
that guy got in his.  He was probably using a older version.  Mine was on
4.1.1 so everyone should be switching to OO from the looks of it.

OO Procedural
3.22   2.87
3.09   3.05
2.91   3.00
2.88   2.99
3.08   3.09
3.25   3.04
2.97   2.94
2.94   3.01
3.05   2.90
3.07   2.96

3.05   2.99 avg

-Original Message-
From: Remy Dufour [mailto:[EMAIL PROTECTED]]
Sent: June 27, 2002 1:34 PM
To: SP; Kondwani Spike Mkandawire; [EMAIL PROTECTED]
Subject: Re: [PHP] Re: PHP and OOP


I've tested thecode and there is what i've got
Proceduraltook 1.24408602715 seconds
OOtook 1.24240803719 seconds
Here is the code. Test it by yourself
?phpfunction getmicrotime(){list($usec, $sec) = explode(
,microtime());return ((float)$usec + (float)$sec);}function
icount($vs) {$var=0;while($count  $vs) {
$count++;}}$time_start = getmicrotime();icount(100);
echo Proceduralbr took . (getmicrotime() - $time_start) . secondsbr;
class count {function icount($vs) {$var=0;
while($count  $vs) {$count++;}}}
$time_start = getmicrotime();$icount = new count;
$icount-icount(100);echo brOObr took . (getmicrotime() -
$time_start) . seconds;?

 OO is slower then procedural.  You can test that out yourself or look at
 this article where the guy did a very basic test.  Maybe they will fix the
 speed problem by the time php5 comes around.
 http://www.phpbeginner.com/columns/demitrious/objects/8



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




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




RE: [PHP] Re: PHP and OOP

2002-06-27 Thread Demitrious S. Kelly

Comparison (do not compare the speeds between the versions of php as
they are on different servers under different loads.) The only
conclusion that I can draw from this so far is that different versions
of php handle these situations differently, newer versions may handle
OOP code better that proc code - this is just conjecture of course.  It
also may not be realistic to judge so harshly and quickly on benchmarks
like this. This kind of code isn't very real world when you get right
down to it. Other factors may also be in play - the kind of functions
used inside the proc/obj, types of variables - how about nested objects
- different kinds of loops - etc etc etc. It's a hard comparison to make
- as I do not have time to compile many versions of php on a given
machine and run the tests at the moment. Maybe someone with a bit of
time to spare would help shed some light on the subject?

If I get a chance I will look into the problem further. And I will have
the results amended to my article on phpbeginner.com (or the results of
the person (people?) who sheds light on the subject for us) so stay
tuned to the website  and I'll try to get something more definitive
soon.

Cheers everyone!

OOP: 
PHP Version: 4.1.2 Took 70.311300992966 seconds
PHP Version: 4.2.1 Took 76.400364041328 seconds
?php

set_time_limit(0);

class count {
function icount($vs) {
$var=0;
while($count  $vs) {
$date=time();
$count++;
}
}
}

function getmicrotime(){
list($usec, $sec) = explode( ,microtime());
return ((float)$usec + (float)$sec);
}

$time_start = getmicrotime();
$icount=new count;
$icount-icount(1000); 
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo Took $time seconds;
?

PROC:
PHP Version: 4.1.2 Took 69.567726969719 seconds 
PHP Version: 4.2.1 Took 86.658290982246 seconds
?php

set_time_limit(0);

function getmicrotime(){
list($usec, $sec) = explode( ,microtime());
return ((float)$usec + (float)$sec);
}

function icount($vs) {
$count=0;
while($count  $vs) {
$count++;
$date=time();
}
}

$time_start = getmicrotime();
icount(1000);
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo Took $time seconds;
?

-Original Message-
From: SP [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, June 27, 2002 12:01 PM
To: Remy Dufour; Kondwani Spike Mkandawire; [EMAIL PROTECTED]
Subject: RE: [PHP] Re: PHP and OOP

Never tested it so I tried it out for the fun of it.  I didn't use yours
but
I used the other guy's code on separate pages and did it ten times.  I
guess
I was wrong, I got around 2% difference.  Definitely not the 20%
difference
that guy got in his.  He was probably using a older version.  Mine was
on
4.1.1 so everyone should be switching to OO from the looks of it.

OO Procedural
3.22   2.87
3.09   3.05
2.91   3.00
2.88   2.99
3.08   3.09
3.25   3.04
2.97   2.94
2.94   3.01
3.05   2.90
3.07   2.96

3.05   2.99 avg

-Original Message-
From: Remy Dufour [mailto:[EMAIL PROTECTED]]
Sent: June 27, 2002 1:34 PM
To: SP; Kondwani Spike Mkandawire; [EMAIL PROTECTED]
Subject: Re: [PHP] Re: PHP and OOP


I've tested thecode and there is what i've got
Proceduraltook 1.24408602715 seconds
OOtook 1.24240803719 seconds
Here is the code. Test it by yourself
?phpfunction getmicrotime(){list($usec, $sec) = explode(
,microtime());return ((float)$usec + (float)$sec);}
function
icount($vs) {$var=0;while($count  $vs) {
$count++;}}$time_start = getmicrotime();
icount(100);
echo Proceduralbr took . (getmicrotime() - $time_start) .
secondsbr;
class count {function icount($vs) {$var=0;
while($count  $vs) {$count++;}}
}
$time_start = getmicrotime();$icount = new count;
$icount-icount(100);echo brOObr took . (getmicrotime() -
$time_start) . seconds;?

 OO is slower then procedural.  You can test that out yourself or look
at
 this article where the guy did a very basic test.  Maybe they will fix
the
 speed problem by the time php5 comes around.
 http://www.phpbeginner.com/columns/demitrious/objects/8



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




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




-- 
PHP General

RE: [PHP] Re: PHP and OOP

2002-06-27 Thread Martin Towell

I haven't got around to reading all the other replies yet, so this reply
might already be covered...

So I went to that url - and okay, according to the person writing that page,
there's a ~3sec increase in the time it takes to execute - BUT - that's to
do 1 million iterations, doesn't seem too much of a difference to me.

So that's just .03sec increase per iteration - I'm not too fussed about
that. Compared to easier coding/reading/extensiblity/etc, it's a good trade
off.

Just my 2c worth
Martin

-Original Message-
From: SP [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 27, 2002 11:50 PM
To: Kondwani Spike Mkandawire; [EMAIL PROTECTED]
Subject: RE: [PHP] Re: PHP and OOP


OO is slower then procedural.  You can test that out yourself or look at
this article where the guy did a very basic test.  Maybe they will fix the
speed problem by the time php5 comes around.
http://www.phpbeginner.com/columns/demitrious/objects/8

[snip]

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




RE: [PHP] Re: PHP and OOP

2002-06-27 Thread Demitrious S. Kelly

Php version 4.06 (yet another server)

Obj: Took 72.846336007118 seconds
Proc: Took 72.550191044807 seconds

Yea... I'm coming to the conclusion that unless you're coding for a
REALLY high traffic website this difference does not matter... 

But the again under the circumstances it might matter greatly... its all
situational.

-Original Message-
From: Demitrious S. Kelly [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, June 27, 2002 1:04 PM
To: 'SP'; 'Remy Dufour'; 'Kondwani Spike Mkandawire';
[EMAIL PROTECTED]
Subject: RE: [PHP] Re: PHP and OOP

Comparison (do not compare the speeds between the versions of php as
they are on different servers under different loads.) The only
conclusion that I can draw from this so far is that different versions
of php handle these situations differently, newer versions may handle
OOP code better that proc code - this is just conjecture of course.  It
also may not be realistic to judge so harshly and quickly on benchmarks
like this. This kind of code isn't very real world when you get right
down to it. Other factors may also be in play - the kind of functions
used inside the proc/obj, types of variables - how about nested objects
- different kinds of loops - etc etc etc. It's a hard comparison to make
- as I do not have time to compile many versions of php on a given
machine and run the tests at the moment. Maybe someone with a bit of
time to spare would help shed some light on the subject?

If I get a chance I will look into the problem further. And I will have
the results amended to my article on phpbeginner.com (or the results of
the person (people?) who sheds light on the subject for us) so stay
tuned to the website  and I'll try to get something more definitive
soon.

Cheers everyone!

OOP: 
PHP Version: 4.1.2 Took 70.311300992966 seconds
PHP Version: 4.2.1 Took 76.400364041328 seconds
?php

set_time_limit(0);

class count {
function icount($vs) {
$var=0;
while($count  $vs) {
$date=time();
$count++;
}
}
}

function getmicrotime(){
list($usec, $sec) = explode( ,microtime());
return ((float)$usec + (float)$sec);
}

$time_start = getmicrotime();
$icount=new count;
$icount-icount(1000); 
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo Took $time seconds;
?

PROC:
PHP Version: 4.1.2 Took 69.567726969719 seconds 
PHP Version: 4.2.1 Took 86.658290982246 seconds
?php

set_time_limit(0);

function getmicrotime(){
list($usec, $sec) = explode( ,microtime());
return ((float)$usec + (float)$sec);
}

function icount($vs) {
$count=0;
while($count  $vs) {
$count++;
$date=time();
}
}

$time_start = getmicrotime();
icount(1000);
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo Took $time seconds;
?

-Original Message-
From: SP [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, June 27, 2002 12:01 PM
To: Remy Dufour; Kondwani Spike Mkandawire; [EMAIL PROTECTED]
Subject: RE: [PHP] Re: PHP and OOP

Never tested it so I tried it out for the fun of it.  I didn't use yours
but
I used the other guy's code on separate pages and did it ten times.  I
guess
I was wrong, I got around 2% difference.  Definitely not the 20%
difference
that guy got in his.  He was probably using a older version.  Mine was
on
4.1.1 so everyone should be switching to OO from the looks of it.

OO Procedural
3.22   2.87
3.09   3.05
2.91   3.00
2.88   2.99
3.08   3.09
3.25   3.04
2.97   2.94
2.94   3.01
3.05   2.90
3.07   2.96

3.05   2.99 avg

-Original Message-
From: Remy Dufour [mailto:[EMAIL PROTECTED]]
Sent: June 27, 2002 1:34 PM
To: SP; Kondwani Spike Mkandawire; [EMAIL PROTECTED]
Subject: Re: [PHP] Re: PHP and OOP


I've tested thecode and there is what i've got
Proceduraltook 1.24408602715 seconds
OOtook 1.24240803719 seconds
Here is the code. Test it by yourself
?phpfunction getmicrotime(){list($usec, $sec) = explode(
,microtime());return ((float)$usec + (float)$sec);}
function
icount($vs) {$var=0;while($count  $vs) {
$count++;}}$time_start = getmicrotime();
icount(100);
echo Proceduralbr took . (getmicrotime() - $time_start) .
secondsbr;
class count {function icount($vs) {$var=0;
while($count  $vs) {$count++;}}
}
$time_start = getmicrotime();$icount = new count;
$icount-icount

RE: [PHP] Re: PHP and OOP

2002-06-27 Thread Demitrious S. Kelly

I agree... its trivial when presented as is. But what would be the
difference when you're doing quite a lot more with only 10 iterations?
100? That's something to think about...

-Original Message-
From: Martin Towell [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, June 27, 2002 5:21 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP] Re: PHP and OOP

I haven't got around to reading all the other replies yet, so this reply
might already be covered...

So I went to that url - and okay, according to the person writing that
page,
there's a ~3sec increase in the time it takes to execute - BUT - that's
to
do 1 million iterations, doesn't seem too much of a difference to me.

So that's just .03sec increase per iteration - I'm not too fussed
about
that. Compared to easier coding/reading/extensiblity/etc, it's a good
trade
off.

Just my 2c worth
Martin

-Original Message-
From: SP [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 27, 2002 11:50 PM
To: Kondwani Spike Mkandawire; [EMAIL PROTECTED]
Subject: RE: [PHP] Re: PHP and OOP


OO is slower then procedural.  You can test that out yourself or look at
this article where the guy did a very basic test.  Maybe they will fix
the
speed problem by the time php5 comes around.
http://www.phpbeginner.com/columns/demitrious/objects/8

[snip]

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




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