Re: [PHP] Wierd ass code...

2006-05-15 Thread Chris

Richard Lynch wrote:

On Sat, May 13, 2006 6:37 pm, Rory Browne wrote:


There are some cases where the Error Suppression operator may be
useful in
good code.



Last I checked, you pretty much HAD to use it for pg_fetch_row() since
it does an E_NOTICE when you try to fetch a row beyind the number
available...


FYI - not any more.

I find I have to with imap_open though (should get around to posting a 
bug report about that)..


--
Postgresql & php tutorials
http://www.designmagick.com/

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



Re: [PHP] Wierd ass code...

2006-05-15 Thread Ryan A
Hey Rich,

> > // Add to the running totals
> > @$hits["$username|$subnet"]++;
> > @$bytes["$username|$subnet"]+=$byte;
> > @$baps["$username|$subnet|$this_second"]++;
> > @$bapm["$username|$subnet|$this_minute"]++;
> 
> @ is suppressing the E_NOTICE error message that the
> variables are not
> pre-set.


Yep, I got that.

 
> This is BAD if register_globals is ON as it means
> that somebody would
> use:
>
http://example.com/example.php?hits[user|192.168]=1
> to forge the hit counters


I know, but he's done some funky programming above
that so it cant happen, basically; anybody accessing
the script via get/post etc (the web) would get the
welcome page, but if the script is run as a shell
script then and only then is access granted to the
above part (after meeting other conditions...)


> Homework:
>
http://www.php.net/manual/language.operators.errorcontrol.php

Yes sir

:-)


Thanks!
Ryan


--
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)
-
Fight back spam! Download the Blue Frog.
http://www.bluesecurity.com/register/s?user=bXVzaWNndTc%3D

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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



Re: [PHP] Wierd ass code...

2006-05-15 Thread Richard Lynch
On Sat, May 13, 2006 6:37 pm, Rory Browne wrote:
> There are some cases where the Error Suppression operator may be
> useful in
> good code.

Last I checked, you pretty much HAD to use it for pg_fetch_row() since
it does an E_NOTICE when you try to fetch a row beyind the number
available...

You could use pg_num_rows() but that was slower, since the number of
rows would not necassarily be readily available, as I understand it.

Never did understand why that would do that. [shrug]

Things may well have changed since I looked into this almost a decade
ago...

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] Wierd ass code...

2006-05-15 Thread Richard Lynch
On Sat, May 13, 2006 2:20 pm, Ryan A wrote:
> Been reading some other code that I got from the net,
> and  have come across some wierd looking code, would
> appreciate it if someone could explain it to me:
>
> $hits = array();
> $bytes = array();
> $blocked = array();
> $baps = array();
> $bapm = array();
>
> So far so good then further down:
>
> // Add to the running totals
> @$hits["$username|$subnet"]++;
> @$bytes["$username|$subnet"]+=$byte;
> @$baps["$username|$subnet|$this_second"]++;
> @$bapm["$username|$subnet|$this_minute"]++;

@ is suppressing the E_NOTICE error message that the variables are not
pre-set.

This is BAD if register_globals is ON as it means that somebody would
use:
http://example.com/example.php?hits[user|192.168]=1
to forge the hit counters

The rest of it is just funky array indexes, and the ++ operator to add
1 to each thingie.

Homework:
http://www.php.net/manual/language.operators.errorcontrol.php

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] Wierd ass code...

2006-05-15 Thread Gonzalo Monzón

Robin Vickery escribió:


On 14/05/06, Gonzalo Monzón <[EMAIL PROTECTED]> wrote:


Satyam escribió:
> Of course, another possibility is that the author does not know how to
> handle multidimensional arrays (just to say it before anyone else
> points an obvious alternative)
>

I don't think the author does not know how to handle multidimensional
arrays. I thought the author was more concerned about performance than
other issues people like as coding "beautifuly"...  Maybe author's
approach is weird, but its twice faster in the worst case!!

Sure the author only needs to loop the whole array and doesn't need
multi-dimensional approach... 'cause its a lot faster to iterate once
the array is filled!!

Look at the test I've done (below) its seems filling multi-dimensional
arrays is n/2 faster than single dimension, but then when you need to
read the array data, a multi-dimensional approach is always worse than
n*6!!



Your setup is odd. I get much more similar results with both php 4 and 5.

You're also using a more than slightly odd way of iterating through 
the array.


These does exactly the same as your Test functions and are 
considerably faster:


 $v) {
   foreach ($v as $k2 => $v2);
 }
}
?>

Test results from PHP 5.0.5:

Fill style A, bidimensional array: 3.0747
Iteration style A, bidimensional array: 2.4385
Total time style A: 5.5135

Fill style B, single-dimension array: 4.6502
Iteration style B, single-dimension array: 2.3964
Total time style B: 7.047

Fill style C, bidimensional array: 2.5237
Iteration style C, bidimensional array, foreach loop: 1.3415
Total time style C: 3.8656

Test results from PHP 4.4.0:

Fill style A, bidimensional array: 3.2056
Iteration style A, bidimensional array: 2.3848
Total time style A: 5.5907

Fill style B, single-dimension array: 5.1468
Iteration style B, single-dimension array: 2.4016
Total time style B: 7.5488

Fill style C, bidimensional array: 2.6899
Iteration style C, bidimensional array, foreach loop: 1.4073
Total time style C: 4.0976


Hi Robin,

Don't thought my setup is odd. Only I can say my computer maybe isn't as 
faster than yours. I use centrino mobile, windows xp, and test was run 
on php 4.3.9 ( sorry i missed that, thought was 4.3.4)


I know it can be coded to be faster, but my point with that php snippet 
was to compare the same "odd" way with single or multi dimensional 
approaches. Sure $a.$b is faster than "$a$b" and foreach than do while 
(the more if you didn't "use" each element datum!! that's hi - 
optimization! does sense for you using foreach without assigning any 
value from it? yes, you've got them inside foreach $v2 - $k2, but in my 
code i've got too them inside key($v) $v[key($v)], and I do assign them 
to another var, so if you want to compare performance, please to it too! 
anyway I checked this and both multidimensional approaches performs 
pretty equal. )


I didn't code that snippet to the best / faster execution methodology 
for this individual case but a generic "odd" way for comparing both 
cases. The same I did in python, as that language as far more adaptable 
data structures for letting you choose the best for your case needs (I 
could use python numarray (uses C arrays) and I thought you could't beat 
it in PHP or any PHP C extension, but that's far from the purpose of my 
posts.


If do I use $a.$b instead "$a$b" and assign each element key & val from 
foreach in "type c" test, that's what I got: -see below- B & C perform 
nearly equal on total time, of course, the best approach would be highly 
dependent on the real data to use. The only I thing could say about your 
foreach approach is I allways avoided using it in some kind of projects, 
as it does a copy of the data on every iteration, so when using lots of 
objects, huge data, or pass-per-reference had lot of memory performance 
issues using it in php4 -Im speaking about very long-running scripts 
where these issues really care- so do { } while(next()) is the only you 
can use safely...


Notice huge gap in running the type A test in my computer and in yours 
for php 4.4.0 - me 4.3.9, you get 5.59 and I got 13.9, and other tests 
seems my install always performs better than yours! :-) (type b: you 
5.12 - 2.40 = 7.54  me 4.08 - 1.66 = 5.57 that's about 2 secods!!). That 
means to me so this test don't probe nothing, they are all very 
variable... I don't know why that great difference, but I don't think  
the php revision changes from 4.3.9 to 4.4.0 are relevant enought as for 
these performance gaps. We should use a real tests library for choosing 
best case of several runs, and so on...


Anyway these are the results using your test_c modified code with two 
lines added... notice filling type A and C share the same code, and 
there is some gap: 1,97 - 2,16 !


Fill style A, bidimensional array: 1,9726
Iteration style A, bidimensional array: 11,9345
Total time style A: 13,9319

Fill style B, single-dimension array: 4,0895
Iteration style B, single-dimension array: 

Re: [PHP] Wierd ass code...

2006-05-15 Thread Robin Vickery

On 14/05/06, Gonzalo Monzón <[EMAIL PROTECTED]> wrote:

Satyam escribió:
> Of course, another possibility is that the author does not know how to
> handle multidimensional arrays (just to say it before anyone else
> points an obvious alternative)
>

I don't think the author does not know how to handle multidimensional
arrays. I thought the author was more concerned about performance than
other issues people like as coding "beautifuly"...  Maybe author's
approach is weird, but its twice faster in the worst case!!

Sure the author only needs to loop the whole array and doesn't need
multi-dimensional approach... 'cause its a lot faster to iterate once
the array is filled!!

Look at the test I've done (below) its seems filling multi-dimensional
arrays is n/2 faster than single dimension, but then when you need to
read the array data, a multi-dimensional approach is always worse than
n*6!!


Your setup is odd. I get much more similar results with both php 4 and 5.

You're also using a more than slightly odd way of iterating through the array.

These does exactly the same as your Test functions and are considerably faster:

 $v) {
   foreach ($v as $k2 => $v2);
 }
}
?>

Test results from PHP 5.0.5:

Fill style A, bidimensional array: 3.0747
Iteration style A, bidimensional array: 2.4385
Total time style A: 5.5135

Fill style B, single-dimension array: 4.6502
Iteration style B, single-dimension array: 2.3964
Total time style B: 7.047

Fill style C, bidimensional array: 2.5237
Iteration style C, bidimensional array, foreach loop: 1.3415
Total time style C: 3.8656

Test results from PHP 4.4.0:

Fill style A, bidimensional array: 3.2056
Iteration style A, bidimensional array: 2.3848
Total time style A: 5.5907

Fill style B, single-dimension array: 5.1468
Iteration style B, single-dimension array: 2.4016
Total time style B: 7.5488

Fill style C, bidimensional array: 2.6899
Iteration style C, bidimensional array, foreach loop: 1.4073
Total time style C: 4.0976

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



Re: [PHP] Wierd ass code...

2006-05-15 Thread Gonzalo Monzón

Gonzalo Monzón escribió:


Attached results and code. (tested on PHP 4.3.4)
--

Testing bidimensional and single dimension array manipulation

Fill style A, bidimensional array: 2,1603
Iteration style A, bidimensional array: 9,9071
Total time style A: 12,0681

Fill style B, single-dimension array: 4,2362
Iteration style B, single-dimension array: 1,5452
Total time style B: 5,7821

Fill style A, bidimensional array: 2,3548
Iteration style A, bidimensional array: 13,1935
Total time style A: 15,5489

Fill style B, single-dimension array: 4,2891
Iteration style B, single-dimension array: 1,5413
Total time style B: 5,8312

Fill style A, bidimensional array: 2,36
Iteration style A, bidimensional array: 17,8439
Total time style A: 20,2046

Fill style B, single-dimension array: 4,2982
Iteration style B, single-dimension array: 1,5554
Total time style B: 5,8544

Fill style A, bidimensional array: 2,3756
Iteration style A, bidimensional array: 17,8817
Total time style A: 20,2579

Fill style B, single-dimension array: 4,3203
Iteration style B, single-dimension array: 1,5332
Total time style B: 5,8543

Fill style A, bidimensional array: 2,3554
Iteration style A, bidimensional array: 19,2986
Total time style A: 21,6547

Fill style B, single-dimension array: 4,3013
Iteration style B, single-dimension array: 1,5508
Total time style B: 5,8528

I wonder how does PHP4 performs in this test, comparing with Python when 
using dictionaries.
Python wins!  Please, don't flame this as I don't want to mean PHP is 
bad, they are different languages for different approaches. But these 
are the results for this test. Interesting...


Best case A, bi-dimensional:   PHP 12,0681   Python: 1,9930   (n/6,3)
Best case B, single-dimension:   PHP 5,7821   Python: 3,6950   (n/1,56)

Python test, results & code (tested on Python 2.4.3):
---

Fill style A, bidimensional array:  1.742000
Iteration style A, bidimensional array:  0.251000
Total time style A: 1.993000

Fill style B, single-dimension array:  3.414000
Iteration style B, single-dimension array:  0.271000
Total time style B: 3.695000

Fill style A, bidimensional array:  2.073000
Iteration style A, bidimensional array:  0.24
Total time style A: 2.313000

Fill style B, single-dimension array:  3.846000
Iteration style B, single-dimension array:  0.31
Total time style B: 4.166000

Fill style A, bidimensional array:  2.133000
Iteration style A, bidimensional array:  0.251000
Total time style A: 2.384000

Fill style B, single-dimension array:  3.735000
Iteration style B, single-dimension array:  0.35
Total time style B: 4.085000

Fill style A, bidimensional array:  2.144000
Iteration style A, bidimensional array:  0.24
Total time style A: 2.384000

Fill style B, single-dimension array:  3.795000
Iteration style B, single-dimension array:  0.381000
Total time style B: 4.176000
-

import time

def TimeMS():
   return time.time()*1000

def TestA():
   global gTestA
   gTestA = {}
   for a in xrange(0,999):
   gTestA[a] = {}
   for b in xrange(0,999):
   gTestA[a][b] = "%s%s" % (a,b)

def TestB():
   global gTestB
   gTestB = {}
   for a in xrange(0,999):
   for b in xrange(0,999):
   gTestB["%s%s" % (a,b)] = "%s%s" % (a,b)

def TestA2():
   global gTestA
   for a in gTestA:
   for b in gTestA[a]:
   c = gTestA[a][b]

def TestB2():
   global gTestB
   for a in gTestB:
   c = gTestB[a]

# TEST:  
for n in xrange(1,5):

   gTestA = {}
   print "\nFill style A, bidimensional array: ",
   startt = TimeMS()
   TestA()
   print "%f" % ((TimeMS() - startt)/1000)

   print "Iteration style A, bidimensional array: ",
   startt2 = TimeMS()
   TestA2()
   print "%f" % ((TimeMS() - startt2)/1000)
   print "Total time style A: %f" % ((TimeMS() - startt)/1000)

   gTestB = {}
   print "\nFill style B, single-dimension array: ",
   startt = TimeMS()
   TestB()
   print "%f" % ((TimeMS() - startt)/1000)

   print "Iteration style B, single-dimension array: ",
   startt2 = TimeMS()
   TestB2()
   print "%f" % ((TimeMS() - startt2)/1000)
   print "Total time style B: %f" % ((TimeMS() - startt)/1000)

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



Re: [PHP] Wierd ass code...

2006-05-13 Thread Gonzalo Monzón

Satyam escribió:



- Original Message - From: "Satyam" <[EMAIL PROTECTED]>
To: "Ryan A" <[EMAIL PROTECTED]>; "php php" 
Sent: Saturday, May 13, 2006 9:53 PM
Subject: Re: [PHP] Wierd ass code...




- Original Message - From: "Ryan A" <[EMAIL PROTECTED]>
To: "php php" 
Sent: Saturday, May 13, 2006 9:20 PM
Subject: [PHP] Wierd ass code...



Hey,
Been reading some other code that I got from the net,
and  have come across some wierd looking code, would
appreciate it if someone could explain it to me:

$hits = array();
$bytes = array();
$blocked = array();
$baps = array();
$bapm = array();

So far so good then further down:

// Add to the running totals
@$hits["$username|$subnet"]++;
@$bytes["$username|$subnet"]+=$byte;
@$baps["$username|$subnet|$this_second"]++;
@$bapm["$username|$subnet|$this_minute"]++;

What kind of arrays are the above? I have never seen
nor worked with arrays like them before.

If you can point me to a particular place in the
manual or a few URLs too would be appreciated.

Thanks,
Ryan

I don't think there is nothing special with the arrays, he is just 
coding some information into strings, with the vertical bar as 
separator, and using this as the keys to several arrays where he is 
collecting some statistical information, such as (it would seem to me)

- number of hits by user and subnet
- number of bytes by user and subnet
- number of hits per user and subnet per second
- number of hits per user and subnet per  minute

I would assume that the variables $this_second and $this_minute are 
absolute numbers counted from a particular time, not seconds from 0 
to 60 within the minute. Likewise for the minutes.


I assume that the @ in front is to avoid the error of trying to 
increment a value that is not yet set.


I guess that this same thing could have been achieved with 
multidimensional arrays but either concatenating the variables into a 
single string is faster or some other reason that makes sense for the 
application, such as being able to sort by keys in just one operation.


Satyam


Of course, another possibility is that the author does not know how to 
handle multidimensional arrays (just to say it before anyone else 
points an obvious alternative)


Satyam


Hi!

I don't think the author does not know how to handle multidimensional 
arrays. I thought the author was more concerned about performance than 
other issues people like as coding "beautifuly"...  Maybe author's 
approach is weird, but its twice faster in the worst case!!


Sure the author only needs to loop the whole array and doesn't need 
multi-dimensional approach... 'cause its a lot faster to iterate once 
the array is filled!!


Look at the test I've done (below) its seems filling multi-dimensional 
arrays is n/2 faster than single dimension, but then when you need to 
read the array data, a multi-dimensional approach is always worse than 
n*6!! so the total time for setting & getting the data is about n*2 in 
the worse case... Repeating the same operation multiple times, the 
multi-dimensional approach always gets worse performance ??, but 
single-dimension stays performing in a linear way. I think that's really 
interesting!!


Perhaps there are better approaches for iterating over multidimensional 
arrays, but that's what I got in 5 minutes coding. I'd like to hear your 
suggestions about if the author code really worth the pain when 
performance makes sense.


Attached results and code. (tested on PHP 4.3.4)
--

Testing bidimensional and single dimension array manipulation

Fill style A, bidimensional array: 2,1603
Iteration style A, bidimensional array: 9,9071
Total time style A: 12,0681

Fill style B, single-dimension array: 4,2362
Iteration style B, single-dimension array: 1,5452
Total time style B: 5,7821

Fill style A, bidimensional array: 2,3548
Iteration style A, bidimensional array: 13,1935
Total time style A: 15,5489

Fill style B, single-dimension array: 4,2891
Iteration style B, single-dimension array: 1,5413
Total time style B: 5,8312

Fill style A, bidimensional array: 2,36
Iteration style A, bidimensional array: 17,8439
Total time style A: 20,2046

Fill style B, single-dimension array: 4,2982
Iteration style B, single-dimension array: 1,5554
Total time style B: 5,8544

Fill style A, bidimensional array: 2,3756
Iteration style A, bidimensional array: 17,8817
Total time style A: 20,2579

Fill style B, single-dimension array: 4,3203
Iteration style B, single-dimension array: 1,5332
Total time style B: 5,8543

Fill style A, bidimensional array: 2,3554
Iteration style A, bidimensional array: 19,2986
Total time style A: 21,6547

Fill style B, single-dimension array: 4,3013
Iteration style B, single-dimension array: 1,5508
Total time style B: 5,852

Re: [PHP] Wierd ass code...

2006-05-13 Thread Robert Cummings
On Sat, 2006-05-13 at 19:37, Rory Browne wrote:
>
> I would submit that the error suppression operator isn't BAD BAD BAD
> per se - it's just like goto, in that 99% of its use is bad. In the
> absence of a comment justifying it, the error-suppressed expression is
> BAD. 
> 
> There are some cases where the Error Suppression operator may be
> useful in good code. I wouldn't use it to suppress anything more
> serious than E_NOTICE. I don't think I ever used this operator, but if
> I did, i'd explain why there is no possible case where the code could
> emit an E_WARNING or higher. 

Yep I agree with that... the particular usage in the example though was
just laziness :)

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] Wierd ass code...

2006-05-13 Thread Rory Browne

>
> // Add to the running totals
> @$hits["$username|$subnet"]++;
> @$bytes["$username|$subnet"]+=$byte;
> @$baps["$username|$subnet|$this_second"]++;
> @$bapm["$username|$subnet|$this_minute"]++;
>
> What kind of arrays are the above? I have never seen
> nor worked with arrays like them before.
>
> If you can point me to a particular place in the
> manual or a few URLs too would be appreciated.


It looks like the code was written by  an awk programmer, or a programmer of
some language that doesn't natively support multidimensional assoc arrays.

It's just a normal array.. but the author is creating keys on the fly

for which the values area being incremented. And because there's no
error checking for the key not existing previously, he has used the
dirty error suppression operator. BAD BAD BAD CODER! Remember, if an
error occurs and you have a custom error handler, your custom error
handler still gets invoked. OWWIE!



I would submit that the error suppression operator isn't BAD BAD BAD per se
- it's just like goto, in that 99% of its use is bad. In the absence of a
comment justifying it, the error-suppressed expression is BAD.

There are some cases where the Error Suppression operator may be useful in
good code. I wouldn't use it to suppress anything more serious than
E_NOTICE. I don't think I ever used this operator, but if I did, i'd explain
why there is no possible case where the code could emit an E_WARNING or
higher.


Cheers,

Rob.
--
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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




Re: [PHP] Wierd ass code...

2006-05-13 Thread Ryan A
Thanks Rob, Satyam,


I understood the error supression but never came
across arrays where people were creating keys on the
fly like this and incrementing themjust looked a
bit weird to me.

Cheers!
Ryan

--- Robert Cummings <[EMAIL PROTECTED]> wrote:

> On Sat, 2006-05-13 at 15:20, Ryan A wrote:
> > Hey,
> > Been reading some other code that I got from the
> net,
> > and  have come across some wierd looking code,
> would
> > appreciate it if someone could explain it to me:
> > 
> > $hits = array();
> > $bytes = array();
> > $blocked = array();
> > $baps = array();
> > $bapm = array();
> > 
> > So far so good then further down:
> > 
> > // Add to the running totals
> > @$hits["$username|$subnet"]++;
> > @$bytes["$username|$subnet"]+=$byte;
> > @$baps["$username|$subnet|$this_second"]++;
> > @$bapm["$username|$subnet|$this_minute"]++;
> > 
> > What kind of arrays are the above? I have never
> seen
> > nor worked with arrays like them before.
> > 
> > If you can point me to a particular place in the
> > manual or a few URLs too would be appreciated.
> 
> It's just a normal array.. but the author is
> creating keys on the fly
> for which the values area being incremented. And
> because there's no
> error checking for the key not existing previously,
> he has used the
> dirty error suppression operator. BAD BAD BAD CODER!
> Remember, if an
> error occurs and you have a custom error handler,
> your custom error
> handler still gets invoked. OWWIE!
> 
> Cheers,
> Rob.
> -- 
>
..
> | InterJinn Application Framework -
> http://www.interjinn.com |
>
::
> | An application and templating framework for PHP.
> Boasting  |
> | a powerful, scalable system for accessing system
> services  |
> | such as forms, properties, sessions, and caches.
> InterJinn |
> | also provides an extremely flexible architecture
> for   |
> | creating re-usable components quickly and easily. 
> |
>
`'
> 
> 


--
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)
-
Fight back spam! Download the Blue Frog.
http://www.bluesecurity.com/register/s?user=bXVzaWNndTc%3D

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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



Re: [PHP] Wierd ass code...

2006-05-13 Thread Satyam


- Original Message - 
From: "Satyam" <[EMAIL PROTECTED]>

To: "Ryan A" <[EMAIL PROTECTED]>; "php php" 
Sent: Saturday, May 13, 2006 9:53 PM
Subject: Re: [PHP] Wierd ass code...




- Original Message - 
From: "Ryan A" <[EMAIL PROTECTED]>

To: "php php" 
Sent: Saturday, May 13, 2006 9:20 PM
Subject: [PHP] Wierd ass code...



Hey,
Been reading some other code that I got from the net,
and  have come across some wierd looking code, would
appreciate it if someone could explain it to me:

$hits = array();
$bytes = array();
$blocked = array();
$baps = array();
$bapm = array();

So far so good then further down:

// Add to the running totals
@$hits["$username|$subnet"]++;
@$bytes["$username|$subnet"]+=$byte;
@$baps["$username|$subnet|$this_second"]++;
@$bapm["$username|$subnet|$this_minute"]++;

What kind of arrays are the above? I have never seen
nor worked with arrays like them before.

If you can point me to a particular place in the
manual or a few URLs too would be appreciated.

Thanks,
Ryan

I don't think there is nothing special with the arrays, he is just coding 
some information into strings, with the vertical bar as separator, and 
using this as the keys to several arrays where he is collecting some 
statistical information, such as (it would seem to me)

- number of hits by user and subnet
- number of bytes by user and subnet
- number of hits per user and subnet per second
- number of hits per user and subnet per  minute

I would assume that the variables $this_second and $this_minute are 
absolute numbers counted from a particular time, not seconds from 0 to 60 
within the minute. Likewise for the minutes.


I assume that the @ in front is to avoid the error of trying to increment 
a value that is not yet set.


I guess that this same thing could have been achieved with 
multidimensional arrays but either concatenating the variables into a 
single string is faster or some other reason that makes sense for the 
application, such as being able to sort by keys in just one operation.


Satyam
Of course, another possibility is that the author does not know how to 
handle multidimensional arrays (just to say it before anyone else points an 
obvious alternative)


Satyam

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



Re: [PHP] Wierd ass code...

2006-05-13 Thread Robert Cummings
On Sat, 2006-05-13 at 15:20, Ryan A wrote:
> Hey,
> Been reading some other code that I got from the net,
> and  have come across some wierd looking code, would
> appreciate it if someone could explain it to me:
> 
> $hits = array();
> $bytes = array();
> $blocked = array();
> $baps = array();
> $bapm = array();
> 
> So far so good then further down:
> 
> // Add to the running totals
> @$hits["$username|$subnet"]++;
> @$bytes["$username|$subnet"]+=$byte;
> @$baps["$username|$subnet|$this_second"]++;
> @$bapm["$username|$subnet|$this_minute"]++;
> 
> What kind of arrays are the above? I have never seen
> nor worked with arrays like them before.
> 
> If you can point me to a particular place in the
> manual or a few URLs too would be appreciated.

It's just a normal array.. but the author is creating keys on the fly
for which the values area being incremented. And because there's no
error checking for the key not existing previously, he has used the
dirty error suppression operator. BAD BAD BAD CODER! Remember, if an
error occurs and you have a custom error handler, your custom error
handler still gets invoked. OWWIE!

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] Wierd ass code...

2006-05-13 Thread Satyam


- Original Message - 
From: "Ryan A" <[EMAIL PROTECTED]>

To: "php php" 
Sent: Saturday, May 13, 2006 9:20 PM
Subject: [PHP] Wierd ass code...



Hey,
Been reading some other code that I got from the net,
and  have come across some wierd looking code, would
appreciate it if someone could explain it to me:

$hits = array();
$bytes = array();
$blocked = array();
$baps = array();
$bapm = array();

So far so good then further down:

// Add to the running totals
@$hits["$username|$subnet"]++;
@$bytes["$username|$subnet"]+=$byte;
@$baps["$username|$subnet|$this_second"]++;
@$bapm["$username|$subnet|$this_minute"]++;

What kind of arrays are the above? I have never seen
nor worked with arrays like them before.

If you can point me to a particular place in the
manual or a few URLs too would be appreciated.

Thanks,
Ryan

I don't think there is nothing special with the arrays, he is just coding 
some information into strings, with the vertical bar as separator, and using 
this as the keys to several arrays where he is collecting some statistical 
information, such as (it would seem to me)

- number of hits by user and subnet
- number of bytes by user and subnet
- number of hits per user and subnet per second
- number of hits per user and subnet per  minute

I would assume that the variables $this_second and $this_minute are absolute 
numbers counted from a particular time, not seconds from 0 to 60 within the 
minute. Likewise for the minutes.


I assume that the @ in front is to avoid the error of trying to increment a 
value that is not yet set.


I guess that this same thing could have been achieved with multidimensional 
arrays but either concatenating the variables into a single string is faster 
or some other reason that makes sense for the application, such as being 
able to sort by keys in just one operation.


Satyam 


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



[PHP] Wierd ass code...

2006-05-13 Thread Ryan A
Hey,
Been reading some other code that I got from the net,
and  have come across some wierd looking code, would
appreciate it if someone could explain it to me:

$hits = array();
$bytes = array();
$blocked = array();
$baps = array();
$bapm = array();

So far so good then further down:

// Add to the running totals
@$hits["$username|$subnet"]++;
@$bytes["$username|$subnet"]+=$byte;
@$baps["$username|$subnet|$this_second"]++;
@$bapm["$username|$subnet|$this_minute"]++;

What kind of arrays are the above? I have never seen
nor worked with arrays like them before.

If you can point me to a particular place in the
manual or a few URLs too would be appreciated.

Thanks,
Ryan

--
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)
-
Fight back spam! Download the Blue Frog.
http://www.bluesecurity.com/register/s?user=bXVzaWNndTc%3D

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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