php-general Digest 14 Oct 2006 06:33:45 -0000 Issue 4400

2006-10-14 Thread php-general-digest-help

php-general Digest 14 Oct 2006 06:33:45 - Issue 4400

Topics (messages 243100 through 243122):

Re: Send process to background
243100 by: Richard Lynch
243105 by: Jon Anderson
243114 by: Ed Lazor

Re: Socket communications question
243101 by: Richard Lynch
243119 by: Manuel Lemos

Re: readfile() problem
243102 by: Richard Lynch

Re: canon jpegs
243103 by: Richard Lynch
243107 by: Al

Windows ENV['_'] equivalent
243104 by: Richard Lynch
243108 by: Roman Neuhauser
243109 by: M.Sokolewicz
243118 by: Ed Lazor

PHP Denial of service
243106 by: Ryan Barclay
243110 by: Robert Cummings
243112 by: Ryan Barclay
243113 by: Ryan Barclay
243115 by: Robert Cummings
243116 by: Jon Anderson
243121 by: Ed Lazor

Re: Understanding persistent connections...
243111 by: Google Kreme

Re: php mailer part 2
243117 by: Manuel Lemos

A no brainer...
243120 by: Tony Di Croce
243122 by: Larry Garfield

Administrivia:

To subscribe to the digest, e-mail:
[EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]

To post to the list, e-mail:
php-general@lists.php.net


--
---BeginMessage---
On Fri, October 13, 2006 11:05 am, André Medeiros wrote:
 I am working on a backup system that needs to be called through a
 webpage to start the process. I am trying to do this on a
 one-file-only sollution.

 The thing is, the first request to the site needs to start the backup,
 but I didn't want to use any command-line tools, since some of our
 servers rely on safe_mode. Is there any way to send output to the
 browser on this first instance, finish the request, but keeping the
 PHP running and making the backup.

Probably not, at least not in a portable way.

In *some* OS configurations this might work:

?php `backup_script_here.xyz `;?

No promises.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
---End Message---
---BeginMessage---

Richard Lynch wrote:

On Fri, October 13, 2006 11:05 am, André Medeiros wrote:
  

I am working on a backup system that needs to be called through a
webpage to start the process. I am trying to do this on a
one-file-only sollution.

The thing is, the first request to the site needs to start the backup,
but I didn't want to use any command-line tools, since some of our
servers rely on safe_mode. Is there any way to send output to the
browser on this first instance, finish the request, but keeping the
PHP running and making the backup.



Probably not, at least not in a portable way.

In *some* OS configurations this might work:

?php `backup_script_here.xyz `;?

No promises.

  
A hack I've used was to make a standalone script, then call it via curl 
(http://localhost/path/to/script.php) with a timeout set to something 
short. Output can be sent to a file or database somewhere that can be 
read back and deleted later. That isn't pretty though...


jon
---End Message---
---BeginMessage---


On Oct 13, 2006, at 12:12 PM, Richard Lynch wrote:


On Fri, October 13, 2006 11:05 am, André Medeiros wrote:

I am working on a backup system that needs to be called through a
webpage to start the process. I am trying to do this on a
one-file-only sollution.

The thing is, the first request to the site needs to start the  
backup,

but I didn't want to use any command-line tools, since some of our
servers rely on safe_mode. Is there any way to send output to the
browser on this first instance, finish the request, but keeping the
PHP running and making the backup.


Probably not, at least not in a portable way.

In *some* OS configurations this might work:

?php `backup_script_here.xyz `;?

No promises.


In unix, you can run something like this:

script  output.log 

You can call something like that using PHP system calls.

You might be stuck if safe_mode_exec_dir is locked down.  You're  
especially screwed when you remove the option of using command-line  
tools.


If you were to try to use PHP itself to manually get a directory  
listing, open each file, compress it, add it to an archive, etc.,  
you're definitely going the wrong route.
---End Message---
---BeginMessage---
On Fri, October 13, 2006 11:15 am, Jeff Lanzarotta wrote:

How did you open the socket?

Did you check that it's valid?

You've already written to it, right?...

And Java got the data you sent?

One hack would be to try opening one socket just for reading and one
just for writing...

Might work out what's going on from that.

Or, if it works, just live with 2 one-way sockets instead of a 2-way
socket.

 while ($out = socket_read($socket, 2048, PHP_NORMAL_READ))
 {
   echo $out;
 }

 never returns.

 Any ideas?

 -Jeff


 -Jeff

 --
 PHP 

php-general Digest 14 Oct 2006 20:25:45 -0000 Issue 4401

2006-10-14 Thread php-general-digest-help

php-general Digest 14 Oct 2006 20:25:45 - Issue 4401

Topics (messages 243123 through 243147):

Re: OOP slow -- am I an idiot?
243123 by: Tony Marston
243124 by: Tony Marston
243125 by: Tony Marston
243126 by: Tony Marston

Re: Windows ENV['_'] equivalent
243127 by: Stut
243144 by: Ed Lazor

Class returning more than one value
243128 by: Deckard
243129 by: Paul Scott

Re: PHP Denial of service
243130 by: Ryan Barclay
243131 by: Ryan Barclay
243132 by: Ryan Barclay
243133 by: Roman Neuhauser
243146 by: Ed Lazor

Crossing over to the Darkside?
243134 by: Ross
243135 by: Roman Neuhauser
243136 by: Roman Neuhauser
243145 by: Rory Browne
243147 by: Ed Lazor

Retrieving values from array on a class
243137 by: AR
243138 by: Roman Neuhauser
243139 by: AR
243140 by: Roman Neuhauser
243141 by: AR
243142 by: Roman Neuhauser

Re: A no brainer...
243143 by: Ed Lazor

Administrivia:

To subscribe to the digest, e-mail:
[EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]

To post to the list, e-mail:
php-general@lists.php.net


--
---BeginMessage---

Stut [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Tony Marston wrote:
 Stut [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]

 My general approach to designing a system is data-centric. I tend to 
 start by defining the database schema since getting that clear in my 
 head tends to lead me to a decent design.


 What a coincidence! That's exactly my approach, but I've taken it one 
 step further. I always start with a properly normalised database which I 
 can then import into my daa dictionary application. From there I can 
 press a button and create a class file for each database table, and I am 
 ptting the finishing touhes to a procedure whereby I can press another 
 button to generate the scripts which will maintain each table. This means 
 I can get basic transactions up and running without writing a single line 
 of code. All I have to do is edit these files to include business logic 
 and any customisations.

 This level of automation is not possible with some people's OO 
 implementations, so I can only conclude that their approach is not the 
 optimal one.


 Youch!! Your implementation seems to be focused on development efficiency 
 rather than runtime efficience.

Precisely. That is why I said it was adminstrative web applications which 
typically have far fewer users than web sites.

 In all but rare research projects this is backwards for a web-based 
 system.

Wrong again. This is for administrative web applications, the type that were 
previously built as desktop applications. Their function is to get data into 
and out of a database i.e. CRUD applications), not to serve thousands of 
casual vuisitors.

 This is exactly the practice I am trying to discourage. It's a well-known 
 fact that code generators are a poor substitute for real developers.

It depends how you go about it. My code generators fulfil the basics, then 
the programmer's job is to customise it.

 For most projects I don't start out with OOP in mind, but my brain is 
 used to building OOP-style systems so nearly everything I do ends up 
 with a few classes.


 The difference with me is that I don't waste my time with trivial 
 websites, I concentrate on administrative web applications. But even when 
 I wrote the code for my own website at http://www.radicore.org I still 
 used all my database classes as it was far easier than doing it the 
 traditional old-fashioned way

 Trivial websites are where you can get away with using code generators. 
 For anything non-trivial I would not feel comfortable with a 
 jack-of-all-trades-master-of-none-style of code. Now that I think of it 
 I'm quite anal about the quality of my code, so I don't think I'd ever use 
 a code generator - never have before.

I have never liked any of the code generators I have seen created by others, 
but with my general-purpose framework I noticed that a lot of the code that 
I was generating by hand followed a familiar pattern. It was then a simple 
exercise to write a program to generate this same code on command.

Be aware that I am not attempting to generate *all* the code that an 
application will need, just the basics to  get it functioning. This takes 
all the drudgery out of the job and leaves the programmer to do the 
interesting bits.

-- 
Tony Marston
http://www.tonymarston.net
http://www.radicore.org 
---End Message---
---BeginMessage---

Stut [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Ed Lazor wrote:
 On Oct 12, 2006, at 4:36 PM, Stut wrote:
 If I then go on to create an admin interface for the users, I would 
 create another completely separate class 

Re: [PHP] A no brainer...

2006-10-14 Thread Larry Garfield
On Friday 13 October 2006 20:18, Tony Di Croce wrote:
 Is their a slick way of automatically serializing Objects to the session
 when a script exit()'s and de-serialize them in session_start()?

 It seems to me that object oriented PHP might actually be useful if I could
 persist an object across an entire session, and come to think of it, their
 really ought to be an automatic way to do this... (IE, I'd not be suprised
 one bit if its already a feature of PHP that I'm just not aware of)...

 So, is their a way to do this?

class Foo {
...
}

session_start();
$foo = new Foo();
$_SESSION['myfoo'] = $foo;

Ta da.  The catch is the class must be defined before you start the session, 
so that it knows how to deserialize it.

Of course, the cost of serialization and deserialization is non-trivial for 
any data structure that is of interesting size, and you have to keep in mind 
that if you aren't syncing to the database periodically then you will end up 
with stale data objects.  (An issue in any case, but the longer the object 
representing a view of your database exists, the more of a problem it 
becomes.  YMMV depending on the data you're holding.)

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it.  -- Thomas 
Jefferson

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



Re: [PHP] OOP slow -- am I an idiot?

2006-10-14 Thread Tony Marston

Stut [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Tony Marston wrote:
 Stut [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]

 My general approach to designing a system is data-centric. I tend to 
 start by defining the database schema since getting that clear in my 
 head tends to lead me to a decent design.


 What a coincidence! That's exactly my approach, but I've taken it one 
 step further. I always start with a properly normalised database which I 
 can then import into my daa dictionary application. From there I can 
 press a button and create a class file for each database table, and I am 
 ptting the finishing touhes to a procedure whereby I can press another 
 button to generate the scripts which will maintain each table. This means 
 I can get basic transactions up and running without writing a single line 
 of code. All I have to do is edit these files to include business logic 
 and any customisations.

 This level of automation is not possible with some people's OO 
 implementations, so I can only conclude that their approach is not the 
 optimal one.


 Youch!! Your implementation seems to be focused on development efficiency 
 rather than runtime efficience.

Precisely. That is why I said it was adminstrative web applications which 
typically have far fewer users than web sites.

 In all but rare research projects this is backwards for a web-based 
 system.

Wrong again. This is for administrative web applications, the type that were 
previously built as desktop applications. Their function is to get data into 
and out of a database i.e. CRUD applications), not to serve thousands of 
casual vuisitors.

 This is exactly the practice I am trying to discourage. It's a well-known 
 fact that code generators are a poor substitute for real developers.

It depends how you go about it. My code generators fulfil the basics, then 
the programmer's job is to customise it.

 For most projects I don't start out with OOP in mind, but my brain is 
 used to building OOP-style systems so nearly everything I do ends up 
 with a few classes.


 The difference with me is that I don't waste my time with trivial 
 websites, I concentrate on administrative web applications. But even when 
 I wrote the code for my own website at http://www.radicore.org I still 
 used all my database classes as it was far easier than doing it the 
 traditional old-fashioned way

 Trivial websites are where you can get away with using code generators. 
 For anything non-trivial I would not feel comfortable with a 
 jack-of-all-trades-master-of-none-style of code. Now that I think of it 
 I'm quite anal about the quality of my code, so I don't think I'd ever use 
 a code generator - never have before.

I have never liked any of the code generators I have seen created by others, 
but with my general-purpose framework I noticed that a lot of the code that 
I was generating by hand followed a familiar pattern. It was then a simple 
exercise to write a program to generate this same code on command.

Be aware that I am not attempting to generate *all* the code that an 
application will need, just the basics to  get it functioning. This takes 
all the drudgery out of the job and leaves the programmer to do the 
interesting bits.

-- 
Tony Marston
http://www.tonymarston.net
http://www.radicore.org 

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



Re: [PHP] OOP slow -- am I an idiot?

2006-10-14 Thread Tony Marston

Stut [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Ed Lazor wrote:
 On Oct 12, 2006, at 4:36 PM, Stut wrote:
 If I then go on to create an admin interface for the users, I would 
 create another completely separate class called UserCollection to handle 
 more than one user. I may at that point choose to expose any 
 data-massaging methods in User to UserCollection to avoid code 
 duplication, but that would be the extent of the way UserCollection uses 
 the User class since the User class is optimised to work on a single 
 user at any one time.

 We use a similar approach for the user class.  I haven't ever implemented 
 something like the UserCollection class though.  I'm curious about that. 
 Does your UserCollection class extend the basic user class?  Or is it 
 something else entirely; I dunno, maybe UserCollection has a property 
 defined as an array of User class?  I think that's what people were 
 saying earlier in the thread as being a very bad thing in terms of 
 memory utilization, etc.

 Indeed, that would be a very bad thing, unless you've already considered 
 that. I've previously mentioned that I have an ActiveRecord-style 
 implementation for a lot of my DB access. The base class for that system 
 has a static function called FindAll which will return an array of 
 objects. However, it only does a single SQL statement. The base class also 
 has a method LoadFromArray which, shockingly, loads the object from an 
 array. This means that from a single DB request I can get an array of 
 objects each representing one entitity (potentially a row, but not 
 necessarily).

The very idea of one object per row makes me want to throw up. I have one 
object per table, and each object can deal with any number of rows. I don't 
use getters and setters to access the columns from any row, I simply input 
an array (typically one row from the $_POST array) and output an array which 
may contain any number of rows. I find this to be far easier and no less 
efficient.

-- 
Tony Marston
http://www.tonymarston.net
http://www.radicore.org

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



Re: [PHP] OOP slow -- am I an idiot?

2006-10-14 Thread Tony Marston

Ed Lazor [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

 On Oct 13, 2006, at 1:35 AM, Tony Marston wrote:
 What a coincidence! That's exactly my approach, but I've taken it  one 
 step
 further. I always start with a properly normalised database which I  can 
 then
 import into my daa dictionary application. From there I can press a 
 button
 and create a class file for each database table, and I am ptting the
 finishing touhes to a procedure whereby I can press another button to
 generate the scripts which will maintain each table. This means I  can 
 get
 basic transactions up and running without writing a single line of  code. 
 All
 I have to do is edit these files to include business logic and any
 customisations.

 Is the Radicore framework still available?

What do you mean *still*? Since I released it I have never closed it down. I 
am still working on it and releasing improvements. I am just about to 
release some new functionality which will generate more standard code for 
each transaction. Watch my website (see link in my signature) for an 
announcement.

-- 
Tony Marston
http://www.tonymarston.net
http://www.radicore.org 

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



Re: [PHP] OOP slow -- am I an idiot?

2006-10-14 Thread Tony Marston

Ed Lazor [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

 On Oct 13, 2006, at 1:54 AM, Stut wrote:
 Youch!! Your implementation seems to be focused on development 
 efficiency rather than runtime efficience. In all but rare research 
 projects this is backwards for a web-based system. This is exactly  the 
 practice I am trying to discourage. It's a well-known fact that  code 
 generators are a poor substitute for real developers.

 I agree with Stut, but I'd also like to check out a copy of the 
 framework.  It seems like a lot of people are using frameworks now  days 
 and I can't help but wonder if they provide similar performance  as the 
 OOP library that Stut uses.

If you want to build administrative web applications which have a small 
number of users, and where development costs are more important than 
performance of execution (i.e. developer cycles over cpu cycles) then check 
out RADICORE at http://www.radicore.org It is better than Ruby on Rails.

-- 
Tony Marston
http://www.tonymarston.net
http://www.radicore.org 

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



Re: [PHP] Windows ENV['_'] equivalent

2006-10-14 Thread Stut

Ed Lazor wrote:

On Oct 13, 2006, at 11:53 AM, Richard Lynch wrote:

In windows...  There ain't nothing in phpinfo() that matches the
php.exe which I'm running...

How do you handle this?


Not a solution, but an idea...  the dos chdir comand.  Maybe you can run 
it from within your script. It tells you the current working directory 
and you end up indirectly knowing the location of the php.exe that 
you're using.


Unfortunately there's no guarantee that a) the working directory will be 
where the PHP binary is, or b) that the binary is called php.exe.


Richard: AFAIK there is no way to know this under windows without 
writing an extension to tell you.


-Stut

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



[PHP] Class returning more than one value

2006-10-14 Thread Deckard
Hi,

How can i code a class with a function that returns more than one value ?

Any help would be appreciated.

Warm Regards,
Deckard

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



Re: [PHP] Class returning more than one value

2006-10-14 Thread Paul Scott

On Sat, 2006-10-14 at 11:06 +0100, Deckard wrote:
 How can i code a class with a function that returns more than one value ?
 

1. return array();
2. return stdClass;

--Paul

All Email originating from UWC is covered by disclaimer 
http://www.uwc.ac.za/portal/uwc2006/content/mail_disclaimer/index.htm 

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

Re: [PHP] PHP Denial of service

2006-10-14 Thread Ryan Barclay

I have just run a phpinfo and ignore_user_abort is indeed defaulting to off.

It's a pretty heavy php-MySQL script.  I noticed on scripts without the 
MySQL interaction, the server can keep up much better with the forced 
refreshes. 


Are there any other liming settings I can change?

All the best,

Ryan

--
Ryan Barclay

RBFTP Networks Ltd.

DDI: +44 (0)870 490 1870
WWW: http://www.rbftpnetworks.com
BBS: http://forums.rbftpnetworks.com



Robert Cummings wrote:

On Sat, 2006-10-14 at 01:25 +0100, Ryan Barclay wrote:
  

Robert,

Thanks for the reply.  I can't seem to find ignore_user_abort in my 
php.ini.  I would like to do it at server level, rather than individual 
scripts.  Do you know roughly where is it?  I think there were some 
versions with this missing in the ini, which was later fixed.


I'm guessing that if ignore_user_abort is set to on, this could be the 
culprit?


Would simply adding the following to the ini work?:

ignore_user_abort = off



If it's not in your php.ini and not in your source code then it's
already off, unless it's being activated by an http.conf or .htaccess
setting. The default for ignore_user_abort is 0.

What exactly does your script do? It may be possible that whatever task
it is performing prevents PHP from immediately recognizing the user
abort and subsequently terminating.

Cheers,
Rob.
  


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



Re: [PHP] PHP Denial of service

2006-10-14 Thread Ryan Barclay

Jon,

Thanks for the reply.  Yes, ignore_abort is defaulting to off, as stated 
in my other post.  We have a Firebox III 1000 firewall on our external, 
however this does not have any features like this.  I will look into 
iptables.


Thanks,

Ryan

--
Ryan Barclay

RBFTP Networks Ltd.

DDI: +44 (0)870 490 1870
WWW: http://www.rbftpnetworks.com
BBS: http://forums.rbftpnetworks.com



Jon Anderson wrote:

Ryan Barclay wrote:
Thanks for the reply.  I can't seem to find ignore_user_abort in my 
php.ini.  I would like to do it at server level, rather than 
individual scripts.  Do you know roughly where is it?  I think there 
were some versions with this missing in the ini, which was later fixed.


I'm guessing that if ignore_user_abort is set to on, this could be 
the culprit?


Would simply adding the following to the ini work?
Ignore user abort defaults to off, and doesn't necessarily help you if 
the clients don't terminate their connections properly, or they're 
actually trying to DoS you. I think your best bet is to either use 
some lightweight detection in PHP (and maybe send an HTTP error header 
if you're getting hit), or better yet, use a firewall if one is 
available to prevent the connections from even getting to your 
webserver and wasting its resources. (If your server is running on 
Linux, iptables should be able to do what you need, and there are more 
complicated solutions too.)


jon


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



Re: [PHP] PHP Denial of service

2006-10-14 Thread Ryan Barclay
It hasn't actually been attempted.  However, if a couple of a users were 
to hold the refresh, the page generation times would go up ridiculously 
and clients would be waiting over 20sec for pages.  As mentioned, it's a 
very heavy php-mysql script with lots of queries.


Ryan

--
Ryan Barclay

RBFTP Networks Ltd.

DDI: +44 (0)870 490 1870
WWW: http://www.rbftpnetworks.com
BBS: http://forums.rbftpnetworks.com



Ed Lazor wrote:


On Oct 13, 2006, at 2:16 PM, Ryan Barclay wrote:

A simple question I imagine, but I am wondering how I would combat 
DoS attacks by users holding the REFRESH key on their browsers?


I have reproduced this error on a PHP-MYSQL website and when I hold 
the REFRESH key on for a while, page gen times shoot up dramatically 
and hundreds of processes are created.


Is there a way I can stop this/limit the connections/processes in 
apache conf/php.ini?


Apache.conf ThreadsPerChild?


What can I do to combat this method of DoS?


How do you consider this a DoS attack?  Are you seeing servers 
crippled because a user or a couple of users keep hitting the refresh 
key?  Honestly, it seems extreme.  Your server should be able to 
handle much higher loads than that, especially when PHP starts caching 
pages, etc..  I would start double checking the server config, etc..


Also, if you're really worried about someone attacking a site like 
this, you could just take advantage of PHP's auto_prepend to 
automatically log the IP and a time stamp of each page request... and 
if the last page request is within N seconds of the current request, 
you just redirect the user to a page that says something like server 
busy, try again in a moment.


-Ed




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



Re: [PHP] PHP Denial of service

2006-10-14 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2006-10-13 22:16:18 +0100:
 A simple question I imagine, but I am wondering how I would combat DoS 
 attacks by users holding the REFRESH key on their browsers?
 
 I have reproduced this error on a PHP-MYSQL website and when I hold the 
 REFRESH key on for a while, page gen times shoot up dramatically and 
 hundreds of processes are created.
 
 Is there a way I can stop this/limit the connections/processes in apache 
 conf/php.ini?
 
 What can I do to combat this method of DoS?

I haven't tried it, but perhaps this would work:

apache-1.3: http://dominia.org/djao/limitipconn.html
apache-2.0: http://dominia.org/djao/limitipconn2.html

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



[PHP] Crossing over to the Darkside?

2006-10-14 Thread Ross
Hello,

Having used php for a while now and am fairly competent I was persuaded by a 
collegue to look into asp.net.  I decided to download the free trial of 
VS2005 and start with a few tutorials.

I am very suprised how easy  things like user auhtentication and form 
validation is. Literally in minutes. Even though I have written a similar 
script many times for php there is always some tweeking or modifying 
required before it fits the project. The asp object model is far superior, 
something that PHP developers can't really argue against.

Now I know asp .net is not ideal for all projects but I am now thinking that 
there are some projects that would be suited to the use of .net and the 
development time would be greatly reduced. I would like to know


-What is planned for the next version of PHP?
-How many of  you use both of the technologies?
-What influences your decision when using either ASP, .NET, or PHP


I know people feel very strongly about PHP, however I don't want to start an 
argument, just want a decent discussion,


Regards,


R.

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



Re: [PHP] Crossing over to the Darkside?

2006-10-14 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2006-10-14 13:52:50 +0100:
 Having used php for a while now and am fairly competent I was persuaded by a 
 collegue to look into asp.net.  I decided to download the free trial of 
 VS2005 and start with a few tutorials.
 
 I am very suprised how easy  things like user auhtentication and form 
 validation is. Literally in minutes. Even though I have written a similar 
 script many times for php there is always some tweeking or modifying 
 required before it fits the project.

 The asp object model is far superior, 

That's a comparision of code you wrote in PHP with code Microsoft
programmers wrote in C#, and has nothing to do with PHP.

 something that PHP developers can't really argue against.

It's hard to say either way since you didn't show us your code.

Are you aware that you're comparing libraries, not programming
languages?  There's a gazillion authentication libraries written
in PHP to choose from if you can't write one yourself.
 
 Now I know asp .net is not ideal for all projects but I am now
 thinking that there are some projects that would be suited to the use
 of .net and the development time would be greatly reduced.

Well, libraries boost development.

 I would like to know
 
 -What is planned for the next version of PHP?
 -How many of  you use both of the technologies?
 -What influences your decision when using either ASP, .NET, or PHP

License.
 
-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



Re: [PHP] Crossing over to the Darkside?

2006-10-14 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2006-10-14 16:53:34 +:
 # [EMAIL PROTECTED] / 2006-10-14 13:52:50 +0100:
  -What influences your decision when using either ASP, .NET, or PHP
 
 License.

Scratch that, TCO is it. License is a mere contributor to TCO.

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



[PHP] Retrieving values from array on a class

2006-10-14 Thread AR
Hello,

Sorry for the newbie question :(

I have this class named returnConfigParams that returns an array
called $values through a function called getMySQLParams().

My question is how to retrieve the values of the array from the file
that calls the class.

I have:

$params_file = New returnConfigParams;
$params_file-getMySQLParams();
print($params_file[0]);

but doesn't work :(

Help me please.

I'm stuck on this for two hours and didn't find nothing on Google that
could help me.

Cheers,
AR

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



Re: [PHP] Retrieving values from array on a class

2006-10-14 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2006-10-14 15:55:57 +0100:
 Hello,
 
 Sorry for the newbie question :(
 
 I have this class named returnConfigParams that returns an array
 called $values through a function called getMySQLParams().
 
 My question is how to retrieve the values of the array from the file
 that calls the class.
 
 I have:
 
 $params_file = New returnConfigParams;
 $params_file-getMySQLParams();
 print($params_file[0]);

var_dump($params_file-getMySQLParams());

You said the method returns the data, right?

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



Re: [PHP] Retrieving values from array on a class

2006-10-14 Thread AR
Hello,

 I have this class named returnConfigParams that returns an array
 called $values through a function called getMySQLParams().

 My question is how to retrieve the values of the array from the file
 that calls the class.

 I have:

 $params_file = New returnConfigParams;
 $params_file-getMySQLParams();
 print($params_file[0]);
 
 var_dump($params_file-getMySQLParams());
 
 You said the method returns the data, right?
Yes, it returns an array called $values.
My problem is how to access the individual member of the array.

Thanks in advance.

Cheers,
AR

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



Re: [PHP] Retrieving values from array on a class

2006-10-14 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2006-10-14 16:28:57 +0100:
 Hello,
 
  I have this class named returnConfigParams that returns an array
  called $values through a function called getMySQLParams().
 
  My question is how to retrieve the values of the array from the file
  that calls the class.
 
  I have:
 
  $params_file = New returnConfigParams;
  $params_file-getMySQLParams();
  print($params_file[0]);
  
  var_dump($params_file-getMySQLParams());
  
  You said the method returns the data, right?
 Yes, it returns an array called $values.
 My problem is how to access the individual member of the array.

Just like you'd access members of any other array.

$whatever = $params_file-getMySQLParams();
print($whatever[0]);

This is a matter of basic rules of the language. Did you know
most of the grammer is described in the manual?

http://www.php.net/manual/en/langref.php 

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



Re: [PHP] Retrieving values from array on a class

2006-10-14 Thread AR
Hello,

 Just like you'd access members of any other array.
 
 $whatever = $params_file-getMySQLParams();
 print($whatever[0]);
 
 This is a matter of basic rules of the language. Did you know
 most of the grammer is described in the manual?
Sure, i already tried that, but it doesn't works.
All i get is a blank page.

BTW, here is my class:

class returnConfigParams
 {

  var $a;
  var $b;
  var $c;
  var $d;


  function getMySQLParams()
   {
include($_SERVER['DOCUMENT_ROOT']./properties.php);

$values = array(0 = $a, 1 = $b, 2 = $c, 3 = $d);

return($values);

  }

}

Cheers,
AR

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



Re: [PHP] Retrieving values from array on a class

2006-10-14 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2006-10-14 16:42:37 +0100:
  Just like you'd access members of any other array.
  
  $whatever = $params_file-getMySQLParams();
  print($whatever[0]);
  
  This is a matter of basic rules of the language. Did you know
  most of the grammer is described in the manual?

 Sure, i already tried that, but it doesn't works.
 All i get is a blank page.
 
 BTW, here is my class:
 
 class returnConfigParams
  {
 
   var $a;
   var $b;
   var $c;
   var $d;
   
 
   function getMySQLParams()
{
 include($_SERVER['DOCUMENT_ROOT']./properties.php);
   
 $values = array(0 = $a, 1 = $b, 2 = $c, 3 = $d);
   
 return($values);
 
   }
 
 }

since you don't say what's in the included file, I'll assume
it's empty. $a will be unset and print($rCP-getMySQLParams())
will print nothing ().

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



Re: [PHP] A no brainer...

2006-10-14 Thread Ed Lazor


Of course, the cost of serialization and deserialization is non- 
trivial for
any data structure that is of interesting size, and you have to  
keep in mind
that if you aren't syncing to the database periodically then you  
will end up
with stale data objects.  (An issue in any case, but the longer the  
object

representing a view of your database exists, the more of a problem it
becomes.  YMMV depending on the data you're holding.)


Has anyone done tests on the difference between the value and  
performance of serializing data structures versus just pulling the  
data from the database?


PHP stores session data in files by default.  There's gotta be a  
performance hit for the file access.  If you store session data in  
MySQL, you're still making a DB query.  It seems to me that the  
performance is almost the same, which means grabbing the current  
record ends up better because you avoid stale data.  What do you think?


-Ed

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



Re: [PHP] Windows ENV['_'] equivalent

2006-10-14 Thread Ed Lazor


On Oct 14, 2006, at 2:09 AM, Stut wrote:

Unfortunately there's no guarantee that a) the working directory  
will be where the PHP binary is, or b) that the binary is called  
php.exe.


Richard: AFAIK there is no way to know this under windows without  
writing an extension to tell you.


-Stut


Wouldn't it be an easy task of PHP checking the results to see if  
file_exists?  That would resolve the first part, but it might  
indirectly tell you whether you're using php.exe.  If the file_exists  
fails, then you can probably assume you're using the dll.  I know...  
a hacked solution, but maybe it will work?


-Ed

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



Re: [PHP] Crossing over to the Darkside?

2006-10-14 Thread Rory Browne

On 10/14/06, Ross [EMAIL PROTECTED] wrote:


Hello,

Having used php for a while now and am fairly competent I was persuaded by
a
collegue to look into asp.net.  I decided to download the free trial of
VS2005 and start with a few tutorials.

I am very suprised how easy  things like user auhtentication and form
validation is. Literally in minutes. Even though I have written a similar
script many times for php there is always some tweeking or modifying
required before it fits the project. The asp object model is far superior,
something that PHP developers can't really argue against.



That's a bit like saying that apples are better than oranges. PHP and
ASP.NET, while they were designed to server similar, but not identical
purposes, are different tools. PHP is a programming language, but ASP.NET is
a platform, built on the dotNET framework. You could compare something like
CakePHP to ASP.NET, in pretty much the same way as you could compare PHP
itself to C#.


Now I know asp .net is not ideal for all projects but I am now thinking that

there are some projects that would be suited to the use of .net and the
development time would be greatly reduced. I would like to know



Unless dotNET is a total absolute piece of crap, them I'm sure there are
some things that are better suited to the ASP.NET than to their PHP
counterpart. I suspect this would be mainly things that integrate with other
MS technologies.


-What is planned for the next version of PHP?



Google is good for you.
http://www.corephp.co.uk/archives/19-Prepare-for-PHP-6.html

-How many of  you use both of the technologies?

-What influences your decision when using either ASP, .NET, or PHP



The first thing it would depend on would be whether I wanted a framework or
a programming language. If I wanted a framework I'd go with ( out of the
above choices ) ASP.NET, where as if I wanted a programming language I'd go
for PHP. Given the choice however, I'd go with a PHP based framework for
websites, unless they had to integrate with windos services.

I don't currently know ASP.NET enough to use it for production purposes,
added to the fact that most of our machines are Solaris, and not Windos.

I know people feel very strongly about PHP, however I don't want to start an

argument, just want a decent discussion,



You serious? I would never have thought people on the PHP mailing list would
have any interest at all on PHP.


Re: [PHP] PHP Denial of service

2006-10-14 Thread Ed Lazor


On Oct 14, 2006, at 4:05 AM, Ryan Barclay wrote:

It hasn't actually been attempted.  However, if a couple of a users  
were to hold the refresh, the page generation times would go up  
ridiculously and clients would be waiting over 20sec for pages.  As  
mentioned, it's a very heavy php-mysql script with lots of queries.


I see what you're talking about.  Does everyone need live data for  
each page request?  It seems like a great opportunity for data / page  
caching.  I'm trying to remember the name of the caching tool I used,  
but I ran into something similar on one of my websites a few years  
ago.  Each page was dynamic and the server load was high.  I  
installed caching and pages would only update occasionally... meaning  
that users received pages from the cache, instead of each page  
getting processed with each request.  You could also try a reverse  
proxy with apache to do something similar.  The limit IP stuff from  
Roman also looks interesting.


-Ed

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



Re: [PHP] Crossing over to the Darkside?

2006-10-14 Thread Ed Lazor
I agree with Roman and Rory's comments, but I figure I might be able  
to add something, so here goes...


On Oct 14, 2006, at 5:52 AM, Ross wrote:


I am very suprised how easy  things like user auhtentication and form
validation is. Literally in minutes. Even though I have written a  
similar

script many times for php there is always some tweeking or modifying
required before it fits the project.


Checkout :
- Zend Studio
- Zend Platform
- Zend Framework
- Dreamweaver

Google search:
- PHP Framework
- PHP library

Also checkout Ruby on Rails.  Last, but not least, search the PHP  
mailing list for other available PHP frameworks for leads.


Keep in mind that editors may save you some work, but they often use  
a generic approach - bloated code, less efficient code, code that  
doesn't meet the specific needs of your project, code that's  
difficult to change without fighting the editor, and code that's more  
difficult to troubleshoot when you run into problems.  Some people  
are actually faster when coding manually, but that applies to C# just  
as much as it does to PHP.



The asp object model is far superior,
something that PHP developers can't really argue against.


On what basis are you saying one is superior?  It sounds like you're  
still trying to learn the differences between your options in order  
to choose which one to focus on.  Please list individual reasons for  
the superiority that you're talking about and give people a chance to  
provide counter arguments or  counter examples.  Every language,  
development platform, and development library has strengths and  
weaknesses.


Now I know asp .net is not ideal for all projects but I am now  
thinking that
there are some projects that would be suited to the use of .net and  
the

development time would be greatly reduced.


Sure, but the same thing could be said for PHP and some of it's  
available development tools.



I would like to know


-What is planned for the next version of PHP?


In case you're not already checking, you'll have a more balanced  
comparison if you also find out what's planned for the next version  
of ASP or .NET.



-How many of  you use both of the technologies?


I do.  It's more expensive.  There's a lot more work in applying  
updates.  There's also a lot more work to stay current with changes  
in technology; Jack of all trades, master of none.



-What influences your decision when using either ASP, .NET, or PHP


The individual needs of each project.  It's usually best to stick  
with whatever the customer is using if they already have a large  
investment in a particular technology.  However, it is sometimes cost  
effective to switch if the customer can afford it - Google PHP  
versus ASP or PHP versus .NET for plenty of examples.  Google  
Linux versus Windows; this ties into the debate.  Compare the cost  
of hiring developers for each of the technologies.  Compare the cost  
of hosting on Linux versus hosting on Windows.  Compare the security  
of IIS versus Apache.  And, like someone else mentioned, compare your  
value in being able to develop on one platform versus your value in  
being able to develop for one server platform versus your value in  
being able to develop for all of the server platforms that Apache/PHP  
work under.  I've seen examples of .NET being implemented under UNIX;  
they didn't work all that well from what I saw, but researching this  
might also add to your pool of knowledge on which direction to go.


-Ed

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



[PHP] Regular expressions

2006-10-14 Thread Morten Twellmann
I'm trying to understand these regular expressions, but I can't make them
work...

All I want to do, is to find the first occurrence of some text inside the
HTML tags h1 and /h1.

Example string: pOctober 14, 2006/ph1Welcome to my
homepage/h1pWe're happy to announce.../p

must return:

Welcome to my homepage


I tried with:

preg_match('h1\b[^]*(.*?)/h1', h1Welcome to my homepage/h1,
$matches, PREG_OFFSET_CAPTURE);
print_r($matches);

but got nothing...

Can anyone tell me how to do this?

(I tried the above expression in EditPad Pro 6 and it worked...!)

Sincerely,

Morten Twellmann

Re: [PHP] A no brainer...

2006-10-14 Thread Larry Garfield
On Saturday 14 October 2006 11:02, Ed Lazor wrote:
  Of course, the cost of serialization and deserialization is non-
  trivial for
  any data structure that is of interesting size, and you have to
  keep in mind
  that if you aren't syncing to the database periodically then you
  will end up
  with stale data objects.  (An issue in any case, but the longer the
  object
  representing a view of your database exists, the more of a problem it
  becomes.  YMMV depending on the data you're holding.)

 Has anyone done tests on the difference between the value and
 performance of serializing data structures versus just pulling the
 data from the database?

 PHP stores session data in files by default.  There's gotta be a
 performance hit for the file access.  If you store session data in
 MySQL, you're still making a DB query.  It seems to me that the
 performance is almost the same, which means grabbing the current
 record ends up better because you avoid stale data.  What do you think?

 -Ed

It depends on what your data is.  

Is your data basic (a few elements in a linear array) or complex (a deeply 
nested multi-dimensional array or complex object?)  Deserializing a complex 
data structure can get expensive.

Is your data built by a single simple query against the database, a single but 
very complex query with lots of joins and subqueries, or a bunch of separate 
queries over the course of the program?  A single SQL query for cached data 
is likely faster than lots of little queries.

Is your data something that's going to change every few seconds, every few 
minutes, or every few days?  Caching something that will change by your next 
page request anyway is a waste of cycles.

Is your data needed on every page load?  Putting a complex data structure into 
the session if you only need it occasionally is a waste of cycles.  You're 
better off rebuilding it each time or implementing your own caching mechanism 
that only loads on demand.

There is no general answer here.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it.  -- Thomas 
Jefferson

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



Re: [PHP] Retrieving values from array on a class

2006-10-14 Thread Kevin Waterson

This one time, at band camp, Roman Neuhauser wrote:


BTW, here is my class:

class returnConfigParams
{

 var $a;
 var $b;
 var $c;
 var $d;


 function getMySQLParams()
  {
   include($_SERVER['DOCUMENT_ROOT']./properties.php);

   $values = array(0 = $a, 1 = $b, 2 = $c, 3 = $d);

   return($values);

 }

}


Why not a static method?
Create a config singleton and you can have an instance of your class
available anywhere by simply using

config::getInstance()


class config{

/*** Declare instance ***/
private static $instance = NULL;

/**
*
* the constructor is set to private so
* so nobody can create a new instance using new
*
*/
private function __construct() {
  /*** nothing to see, move along ***/
}

/**
*
* Return an array instance
*
* @access public
*
* @return array
*
*/
public static function getInstance() {

if (!self::$instance)
{
/*** set this to the correct path and add some error checking ***/
include($_SERVER['DOCUMENT_ROOT']./properties.php);
self::$instance = array($a, $b, $C);
}
return self::$instance;
}

/**
*
* Like the constructor, we make __clone private
* so nobody can clone the instance
*
*/
private function __clone(){
}

} /*** end of class ***/



Just a thought
Kevin

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



Re: [PHP] A no brainer...

2006-10-14 Thread Ed Lazor


On Oct 14, 2006, at 10:00 AM, Tony Di Croce wrote:

I think that the cost of de-serializing a session stored in files  
should be significantly LESS than the cost of doing so through a  
database, for the following reasons:


1) The db will need to parse querys. Not an issue for files.
2) The session ID will tell PHP what file to open in O(1).
3) The entire session needs to be de-serialized, not just some  
portion of it. The database is optimized for returning subsets of  
all the data.


Sorry Tony, I should have been more clear.  I already know that  
storing session data in MySQL is faster than storing it in files.  I  
know that goes against what you're saying, but there are some  
examples if you Google PHP MySQL session performance.  One of the  
more interesting examples is http://shiflett.org/articles/guru-speak- 
jan2005.  PHP session management defaults to files because it's more  
portable and the performance difference doesn't matter for small  
sites with few concurrent users.  MySQL also provides better  
scaleability and security for session data.


On Oct 14, 2006, at 2:51 PM, Larry Garfield wrote:

It depends on what your data is.

Is your data basic (a few elements in a linear array) or complex (a  
deeply
nested multi-dimensional array or complex object?)  Deserializing a  
complex

data structure can get expensive.

Is your data built by a single simple query against the database, a  
single but
very complex query with lots of joins and subqueries, or a bunch of  
separate
queries over the course of the program?  A single SQL query for  
cached data

is likely faster than lots of little queries.

Is your data something that's going to change every few seconds,  
every few
minutes, or every few days?  Caching something that will change by  
your next

page request anyway is a waste of cycles.

Is your data needed on every page load?  Putting a complex data  
structure into
the session if you only need it occasionally is a waste of cycles.   
You're
better off rebuilding it each time or implementing your own caching  
mechanism

that only loads on demand.

There is no general answer here.


Good points Larry.  I have to look back, but I think we were  
originally talking about basic user data.  ie. the user logs into the  
site and we store their login information and access rights in a  
session.  That seems like basic enough information that it's better  
to just store the user id in session data and grab the rest of their  
information from the db - not much of a difference in performance,  
plus you end up avoiding stale data.  Anyway, I like your distinction  
between simple and complex objects.


-Ed

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



Re: [PHP] Regular expressions

2006-10-14 Thread Penthexquadium
On Sat, 14 Oct 2006 23:19:13 +0200, Morten Twellmann [EMAIL PROTECTED] 
wrote:
 I'm trying to understand these regular expressions, but I can't make them
 work...
 
 All I want to do, is to find the first occurrence of some text inside the
 HTML tags h1 and /h1.
 
 Example string: pOctober 14, 2006/ph1Welcome to my
 homepage/h1pWe're happy to announce.../p
 
 must return:
 
 Welcome to my homepage
 
 
 I tried with:
 
 preg_match('h1\b[^]*(.*?)/h1', h1Welcome to my homepage/h1,
 $matches, PREG_OFFSET_CAPTURE);
 print_r($matches);
 
 but got nothing...
 
 Can anyone tell me how to do this?
 
 (I tried the above expression in EditPad Pro 6 and it worked...!)
 
 Sincerely,
 
 Morten Twellmann

The regex you wrote lacks separator. That PHP statement will occur an
error:

 Warning: preg_match() [function.preg-match]: Unknown modifier ']' in
 /path/file.php on line X

The statement should be:

preg_match(/h1\b[^]*(.*?)\/h1/i, h1Welcome to my homepage/h1,
$matches, PREG_OFFSET_CAPTURE);
print_r($matches);

--
Sorry for my poor English.

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



[PHP] Interchange.

2006-10-14 Thread Jo�o C�ndido de Souza Neto
Hello everyone.

Firstly my apology for the off topic.

I'm a PHP professional since 2000's.

In a quite near future i'm interested in have a professional interchange in 
a foreign country and i'm here to ask you for any information about it.

Thanks a lot. 

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



Re: [PHP] Retrieving values from array on a class

2006-10-14 Thread AR
Hello,

I've rewritten my class as you told me:

--
 class returnConfigParams

 {

  private static $instance = NULL;

  var $a;
  var $b;
  var $c;
  var $d;

  private function __construct() {
  } 

  // function that get the database parameters from properties.php

public static function getInstance() {

if (!self::$instance)
 {
/*** set this to the correct path and add some error checking ***/
  include($_SERVER['DOCUMENT_ROOT']./properties.php);
  self::$instance = array($a, $b, $c, $d);
   }
   return self::$instance;
 }

 private function __clone(){
 }  

}
--

and i'm calling it with

returnConfigParams::getInstance(); (probably wrongly)

The question is how to access the individual elements of the array.

Can someone help me please ?

Cheers,
AR

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



Re: [PHP] Retrieving values from array on a class

2006-10-14 Thread Larry Garfield
On Saturday 14 October 2006 19:09, AR wrote:
 Hello,

 I've rewritten my class as you told me:

 --
  class returnConfigParams

  {

   private static $instance = NULL;

   var $a;
   var $b;
   var $c;
   var $d;

   private function __construct() {
   }

   // function that get the database parameters from properties.php

 public static function getInstance() {

 if (!self::$instance)
  {
 /*** set this to the correct path and add some error checking ***/
   include($_SERVER['DOCUMENT_ROOT']./properties.php);
   self::$instance = array($a, $b, $c, $d);
}
return self::$instance;
  }

  private function __clone(){
  }

 }
 --

 and i'm calling it with

 returnConfigParams::getInstance(); (probably wrongly)

 The question is how to access the individual elements of the array.

I think you're still misunderstanding the concepts involved.

If you have an array assigned to a variable, you access elements of it with 
[].

$foo = array('a', 'b', 'c');

print $foo[0]; // gives 'a'

$bar = array('a' = 'hello', 'b' = 'world');

print $foo['b']; // gives 'world'

http://us3.php.net/manual/en/language.types.array.php

It doesn't matter if you got the array as a return from a function or method 
or not.  

However, what you're doing here is horribly bastardizing classes and 
singletons. :-)  Generally, a getInstance() is used to return an instance of 
a CLASS, not an array.  

If you just want to access the properties of an object, you use the object 
dereference operator, -.

$foo = new returnConfigParams();

print $foo-a; // prints whatever is the value of the property var $a

http://us3.php.net/manual/en/language.oop.php

Of course, if you're trying to get database parameter information, then all of 
this is grossly over-engineered.

properties.php:
?php
$dbsettings['a'] = 'foo';
$dbsettings['b'] = 'bar';
$dbsettings['c'] = 'baz';

index.php (or whatever):
require('properties.php');
And you now have an array $dbsettings, which has the values you need.

Much simpler, and much faster.


-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it.  -- Thomas 
Jefferson

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