[PHP] A php bug or?..

2011-08-08 Thread Andre Polykanine
Hi everyone,

As we all know, count() returns 1 if the variable 
is not an array.
Question is: why in the world does it this? If a variable is *notA* an array, 
it contains *zero* array elements.
You can answer: but no, man, you can say
$x=world;
$y=$x{3}; // $y=l

so the variable is treated or can be treated as an array.
Well. If strings are treated like arrays, why count($x) doesn't return 5 
instead of 1?
Just asking.

-- 
With best regards from Ukraine,
Andre
Skype: Francophile
Blog: http://oire.org/menelion
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion


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



Re: [PHP] A php bug or?..

2011-08-08 Thread Simon J Welsh
On 9/08/2011, at 8:20 AM, Andre Polykanine wrote:

 Hi everyone,
 
As we all know, count() returns 1 if the variable 
 is not an array.
 Question is: why in the world does it this? If a variable is *notA* an array, 
 it contains *zero* array elements.
 You can answer: but no, man, you can say
 $x=world;
 $y=$x{3}; // $y=l
 
 so the variable is treated or can be treated as an array.
 Well. If strings are treated like arrays, why count($x) doesn't return 5 
 instead of 1?
 Just asking.
 
 -- 
 With best regards from Ukraine,
 Andre

I'm assuming it has to do with the value, if not an array or object, being cast 
as an array. Thus, non-false equivalent values get cast into an array of size 1:
?php
var_dump((array)1);
var_dump((array)null);

// Output
array(1) {
  [0]=
  int(1)
}
array(0) {
}

---
Simon Welsh
Admin of http://simon.geek.nz/


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



Re: [PHP] A php bug or?..

2011-08-08 Thread Daniel P. Brown
On Mon, Aug 8, 2011 at 16:20, Andre Polykanine an...@oire.org wrote:
 Hi everyone,

                            As we all know, count() returns 1 if the variable 
 is not an array.
 Question is: why in the world does it this? If a variable is *notA* an array, 
 it contains *zero* array elements.
 You can answer: but no, man, you can say
 $x=world;
 $y=$x{3}; // $y=l

 so the variable is treated or can be treated as an array.
 Well. If strings are treated like arrays, why count($x) doesn't return 5 
 instead of 1?
 Just asking.

Using count() will return the number of items passed in the first
parameter.  If it's an array, each element is an item.  If it's a
string, the string is an item.  If it's an object, logically, the
items depend on what is contained in the object.  However, at no time
does it return the number of characters within a string --- instead,
as you likely know, you'd use strlen().

-- 
/Daniel P. Brown
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

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



Re: [PHP] A php bug or?..

2011-08-08 Thread Andre Polykanine

Hello Daniel,

  
DPB does it return the number of characters within a string --- instead,
DPB as you likely know, you'd use strlen().

  For sure. But I'm asking: why it doesn't return 0 if it is not an array? 
Logically: no array - no items!
-- 
With best regards from Ukraine,
Andre
Skype: Francophile
My blog: http://oire.org/menelion (mostly in Russian)
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion


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



Re: [PHP] A php bug or?..

2011-08-08 Thread Stuart Dallas
On 8 Aug 2011, at 21:41, Andre Polykanine wrote:

 DPB does it return the number of characters within a string --- instead,
 DPB as you likely know, you'd use strlen().
 
  For sure. But I'm asking: why it doesn't return 0 if it is not an array? 
 Logically: no array - no items!


The manual explains what the function does - you may want to check it out cos 
it does the same for all the other functions too.

Returns the number of elements in var. If var is not an array or an object 
with implemented Countable interface, 1 will be returned. There is one 
exception, if var is NULL, 0 will be returned.

IOW, if you pass it a variable, that has one element, so it returns 1. An array 
may have 0 to many elements, and null, logically, has none. Rocket science this 
ain't!

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] A php bug or?..

2011-08-08 Thread Daniel P. Brown
On Mon, Aug 8, 2011 at 16:41, Andre Polykanine an...@oire.org wrote:

      For sure. But I'm asking: why it doesn't return 0 if it is not an array? 
 Logically: no array - no items!

No, actually, if it's a string, it's a single item --- thus, 1.
The documentation should probably reflect that as well.  It wasn't
always this way before, though --- in older version of PHP5 it
returned 0, and in all versions of PHP4 it did as well.

Also, keep in mind that a blank string still constitutes a string
and will return 1, but null or nonexistent variables will still return
0.

-- 
/Daniel P. Brown
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

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



[PHP] Re: php bug from 2003 still alive?! - UTF8 BOM

2009-03-30 Thread Merlin Morgenstern

Hello everybody,

has anybody an idea on how to fix this? Is it really necessary to 
recomplile for utf-8 BOM support?


Regards, Merlin

Merlin Morgenstern wrote:

Hello,

I am experiencing problems with utf-8 and php. There seems to be a 
problem with BOM.


Some postings say that I have to compile php with 
--enable-zend-multibyte. HOwever those postings are very old (2003!).

http://bugs.php.net/bug.php?id=22108

Is this still necessary with the newest php build? If yes, do you 
believe I will run into trouble on sites that are saved in ansi?


Thank you for any hint.

Merlin


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



[PHP] (Apache|php) Bug using modproxy

2006-04-26 Thread Lmwangi
Hi all,
 First time on the list... sorry for any errs.
 I am using mod_proxy to pass requests to an internal server in our
lan. The setup looks like

Enduser---INet_link-Mod_proxy_serverLan---PHP_script

Now,

this  does not work:

Enduser---https---Apache_mod_proxy-http---Destination_server.

* When a user submits a form (php) with a file upload and  $_POST
vars, the $_POST array is mangled (missing) elements and the $_FILES
array is empty

while this works:

 Enduser---http---Apache_mod_proxy-http---Destination_server.

* When a user submits a form with a file upload and  $_POST vars,
Everything is all good
lmwangi

So something bad? happens when you use https in the request. Anyone
able to reproduce this. Is it a php bug (i doubt it) but you never
know until u waddle through the mod_proxy voodoo.
Here is a sample script


snip

?php
if(isset($_POST['btnSubmit'])){
print_r($_POST);
print_r($_FILES);
}
else{
?
!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0
Strict//ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd;

html xmlns=http://www.w3.org/1999/xhtml;
 head
  meta http-equiv=Content-Type content=text/html; charset=utf-8 /
  titlePost Test/title
 /head

body
form action=?php echo $_SERVER['PHP_SELF']? method=post
name=frm_add_content id=frm_add_content
enctype=multipart/form-data
div
input name=id type=hidden value=0 /
input name=MAX_FILE_SIZE type=hidden value=2097152 /
table border=0

tr
td style=white-space: nowrap; background-color:
#CC; align=left valign=top colspan=2bAdd Media/b/td
/tr
tr
td align=right valign=topspan style=color:
#ff*/spanbMedia id/b/td
td valign=top align=leftinput class=inputbox
name=mediaid type=text //td
/tr

tr
td align=right valign=topbMedia File/b/td
td valign=top align=leftinput class=inputbox
name=mms_media type=file //td
/tr
tr
td align=right valign=topspan style=color:
#ff*/spanbSubject/b/td
td valign=top align=leftinput class=inputbox
name=subject type=text //td

/tr
tr
td align=right valign=topbMessage Body/b/td
td valign=top align=lefttextarea
class=inputbox name=msg_body/textarea/td
/tr
tr
tr

td align=right valign=topb/b/td
td valign=top align=leftinput class=button
name=btnClear value=Clear type=reset /nbsp;input
class=button name=btnSubmit value=Submit type=submit //td
/tr
tr
td/td
td align=left valign=topspan style=font-size:80%;
color:#ff;*/spanspan style=font-size:80%; denotes required
field/span/td
/tr

/table
/div
/form
/body
/html
?php
}
?
/snip

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



Re: [PHP] (Apache|php) Bug using modproxy

2006-04-26 Thread Jochem Maas



Lmwangi wrote:

Hi all,
 First time on the list... sorry for any errs.
 I am using mod_proxy to pass requests to an internal server in our
lan. The setup looks like

Enduser---INet_link-Mod_proxy_serverLan---PHP_script

Now,

this  does not work:

Enduser---https---Apache_mod_proxy-http---Destination_server.

* When a user submits a form (php) with a file upload and  $_POST
vars, the $_POST array is mangled (missing) elements and the $_FILES
array is empty

while this works:

 Enduser---http---Apache_mod_proxy-http---Destination_server.


almost definitely not a php problem - maybe using ProxyPass instead of
mod_proxy would work (probably requires https connection on the destination
server) - personally I have used Squid as a reverse proxy for this kind of
setup and let it deal with the https--http conversion - it works but if you
think the Apache stuff is voodoo then I need a new name for the Squid 
configuration
stuff ;-)

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



Re: [PHP] (Apache|php) Bug using modproxy

2006-04-26 Thread Oscar Gosdinski
I have the configuration you described:

browser -- https- mod_proxy - http - php

and i don't have any problem with it. Maybe it's an Apache
misconfiguration. Can you send a snap of your httpd.conf?

On 4/26/06, Lmwangi [EMAIL PROTECTED] wrote:
 Hi all,
  First time on the list... sorry for any errs.
  I am using mod_proxy to pass requests to an internal server in our
 lan. The setup looks like

 Enduser---INet_link-Mod_proxy_serverLan---PHP_script

 Now,

 this  does not work:

 Enduser---https---Apache_mod_proxy-http---Destination_server.

 * When a user submits a form (php) with a file upload and  $_POST
 vars, the $_POST array is mangled (missing) elements and the $_FILES
 array is empty


--
Saludos
Oscar

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



Re: [PHP] (Apache|php) Bug using modproxy

2006-04-26 Thread Jochem Maas

Lmwangi wrote:

Ok thanx. Let me try squid I have posted the mail on the apache
list.. Oh and btw i downgrade my rank. Its no longer voodoo.. So don't
go looking for new name ;-)


ah good - have fun with Squid - but beware it has more arms than you to fight 
with ;-)

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



Re: [PHP] Re: PHP bug within multi. dimensional arrays?

2005-06-07 Thread Jochem Maas

Matthew Weier O'Phinney wrote:

* Merlin [EMAIL PROTECTED]:


Hi there,

I am outputting an multidim. array. That works fine, except one thing. The first 
letter of the value inside dimension 1 always gets printed.


For example:

I fill the arrays:
while ($row = mysql_fetch_object($result)){ 
$cat[$row-main_id][name]= $row-main_name;   
$cat[$row-main_id][$row-sub_id][name] = $row-sub_name;   
   
}



First off, if you're creating associative arrays, you should quote the
keys:

$cat[$row-main_id]['name'] = $row-main_name;

If you don't do so, PHP assumes you're using a constant value for the
key name.



Then I output them:
foreach ($cat AS $maincat){
echo $maincat[name].':';



Quote your keys!



foreach($maincat AS $subcat){



You do realize that the above will also loop over the index 'name',
right?...



echo $subcat[name].$br;



and since it does, the first element in that array is 'name', which
isn't an array, but a string. Since the 'name' constant isn't defined,
it will interpret that as 'true', or 1, and so it takes the first
character of that string.


I think you'll find the 'name' constant evaluates to FALSE, which in turn
casts to zero, which will give you the first element of the given array,
but as you pointed out its a string not an array so you get the first
char (because php allows array-like access to the individual chars in
a string) ... if it had evaluated to TRUE you would be getting the second
char.

the rest of your explaination is spot on.





}
echo $br;
}

Which does result in:

Europe:E
Germany
UK

North America:N
US
CA

As you can see I get the extra letters N and E. Is this an php error or did I do 
something wrong?



So, what you should probably do is create an additional layer in your
multi-dimensional array for the subcategories, and have it of the form
sub_id = sub_name:

$cat[$row-main_id]['subs'][$row-sub_id] = $row-sub_name;

Then loop over that:

foreach ($cat as $main_cat) {
echo $maincat['name'] . :\n;
foreach ($maincat['subs'] as $sub_id = $sub_name) {
echo $sub_name$br; // could also use $sub_id here if
 // desired
}
}



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



[PHP] Re: PHP bug within multi. dimensional arrays?

2005-06-06 Thread Matthew Weier O'Phinney
* Merlin [EMAIL PROTECTED]:
 Hi there,

 I am outputting an multidim. array. That works fine, except one thing. The 
 first 
 letter of the value inside dimension 1 always gets printed.

 For example:

 I fill the arrays:
 while ($row = mysql_fetch_object($result)){   
   $cat[$row-main_id][name]   = $row-main_name;  
   $cat[$row-main_id][$row-sub_id][name] = $row-sub_name;   
 
 }

First off, if you're creating associative arrays, you should quote the
keys:

$cat[$row-main_id]['name'] = $row-main_name;

If you don't do so, PHP assumes you're using a constant value for the
key name.

 Then I output them:
 foreach ($cat AS $maincat){
   echo $maincat[name].':';

Quote your keys!

   foreach($maincat AS $subcat){

You do realize that the above will also loop over the index 'name',
right?...

   echo $subcat[name].$br;

and since it does, the first element in that array is 'name', which
isn't an array, but a string. Since the 'name' constant isn't defined,
it will interpret that as 'true', or 1, and so it takes the first
character of that string.

   }
   echo $br;
 }

 Which does result in:

 Europe:E
 Germany
 UK

 North America:N
 US
 CA

 As you can see I get the extra letters N and E. Is this an php error or did I 
 do 
 something wrong?

So, what you should probably do is create an additional layer in your
multi-dimensional array for the subcategories, and have it of the form
sub_id = sub_name:

$cat[$row-main_id]['subs'][$row-sub_id] = $row-sub_name; 

Then loop over that:

foreach ($cat as $main_cat) {
echo $maincat['name'] . :\n;
foreach ($maincat['subs'] as $sub_id = $sub_name) {
echo $sub_name$br; // could also use $sub_id here if
 // desired
}
}

-- 
Matthew Weier O'Phinney   | WEBSITES:
Webmaster and IT Specialist   | http://www.garden.org
National Gardening Association| http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:[EMAIL PROTECTED] | http://vermontbotanical.org

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



[PHP] Re: PHP bug within multi. dimensional arrays?

2005-06-06 Thread Merlin

Matthew Weier O'Phinney wrote:

* Merlin [EMAIL PROTECTED]:


Hi there,

I am outputting an multidim. array. That works fine, except one thing. The first 
letter of the value inside dimension 1 always gets printed.


For example:

I fill the arrays:
while ($row = mysql_fetch_object($result)){ 
$cat[$row-main_id][name]= $row-main_name;   
$cat[$row-main_id][$row-sub_id][name] = $row-sub_name;   
   
}



First off, if you're creating associative arrays, you should quote the
keys:

$cat[$row-main_id]['name'] = $row-main_name;

If you don't do so, PHP assumes you're using a constant value for the
key name.



Then I output them:
foreach ($cat AS $maincat){
echo $maincat[name].':';



Quote your keys!



foreach($maincat AS $subcat){



You do realize that the above will also loop over the index 'name',
right?...



echo $subcat[name].$br;



and since it does, the first element in that array is 'name', which
isn't an array, but a string. Since the 'name' constant isn't defined,
it will interpret that as 'true', or 1, and so it takes the first
character of that string.



}
echo $br;
}

Which does result in:

Europe:E
Germany
UK

North America:N
US
CA

As you can see I get the extra letters N and E. Is this an php error or did I do 
something wrong?



So, what you should probably do is create an additional layer in your
multi-dimensional array for the subcategories, and have it of the form
sub_id = sub_name:

$cat[$row-main_id]['subs'][$row-sub_id] = $row-sub_name;

Then loop over that:

foreach ($cat as $main_cat) {
echo $maincat['name'] . :\n;
foreach ($maincat['subs'] as $sub_id = $sub_name) {
echo $sub_name$br; // could also use $sub_id here if
 // desired
}
}



This is very helpful and does work. However I did not understand it completley. 
What if I want to add another value, for example name2 or name3.

It looks like this example is limited to id and name.
Could I just add:
$cat[$row-main_id]['subs'][$row-sub_id] = $row-name2;   

Guess not. Can you tell me how to add other fields to the array?

Thank you in advance, Merlin

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



[PHP] Re: PHP bug within multi. dimensional arrays?

2005-06-06 Thread Matthew Weier O'Phinney
* Merlin [EMAIL PROTECTED] :
 Matthew Weier O'Phinney wrote:
  * Merlin [EMAIL PROTECTED] :
   I am outputting an multidim. array. That works fine, except one thing. 
   The first 
   letter of the value inside dimension 1 always gets printed.
  
   For example:
  
   I fill the arrays:
   while ($row = mysql_fetch_object($result)){   
 $cat[$row- main_id][name]  = $row- main_name; 
 $cat[$row- main_id][$row- sub_id][name] = $row- sub_name;
   
   }
  
  First off, if you're creating associative arrays, you should quote the
  keys:
  
  $cat[$row- main_id]['name'] = $row- main_name;
  
  If you don't do so, PHP assumes you're using a constant value for the
  key name.
  
   Then I output them:
   foreach ($cat AS $maincat){
 echo $maincat[name].':';
  
  Quote your keys!
  
 foreach($maincat AS $subcat){
  
  You do realize that the above will also loop over the index 'name',
  right?...
  
  
 echo $subcat[name].$br;
  
  and since it does, the first element in that array is 'name', which
  isn't an array, but a string. Since the 'name' constant isn't defined,
  it will interpret that as 'true', or 1, and so it takes the first
  character of that string.
  
  
 }
 echo $br;
   }
  
   Which does result in:
  
   Europe:E
   Germany
   UK
  
   North America:N
   US
   CA
  
   As you can see I get the extra letters N and E. Is this an php error or 
   did I do 
   something wrong?
  
  So, what you should probably do is create an additional layer in your
  multi-dimensional array for the subcategories, and have it of the form
  sub_id = sub_name:
  
  $cat[$row- main_id]['subs'][$row- sub_id] = $row- sub_name;  
  
  Then loop over that:
  
  foreach ($cat as $main_cat) {
  echo $maincat['name'] . :\n;
  foreach ($maincat['subs'] as $sub_id = $sub_name) {
  echo $sub_name$br; // could also use $sub_id here if
   // desired
  }
  }
  

 This is very helpful and does work. However I did not understand it 
 completley. 
 What if I want to add another value, for example name2 or name3.
 It looks like this example is limited to id and name.
 Could I just add:
 $cat[$row- main_id]['subs'][$row- sub_id] = $row- name2;   

 Guess not. Can you tell me how to add other fields to the array?

You should probably do some studying up on multidimensional and/or
nested arrays so you can get a better handle on this stuff.

If you need to be able to add multiple names for a sub_id, do it as an
array:

$cat[$row-main_id]['subs'][$row-sub_id][] = $row-name1;
$cat[$row-main_id]['subs'][$row-sub_id][] = $row-name2;
$cat[$row-main_id]['subs'][$row-sub_id][] = $row-name3;

However, this will break your loop above -- you'll need another layer of
looping added in:

foreach ($cat as $main_cat) {
echo $maincat['name'] . :\n;
foreach ($maincat['subs'] as $sub_id = $names) {
foreach ($names as $name) {
echo $name$br; // could also use $sub_id here if
 // desired
}
}
}

Hope that helps.

-- 
Matthew Weier O'Phinney   | WEBSITES:
Webmaster and IT Specialist   | http://www.garden.org
National Gardening Association| http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:[EMAIL PROTECTED] | http://vermontbotanical.org

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



[PHP] Re: PHP Bug Problems

2003-10-02 Thread Richard Baskett
on 10/1/03 7:50 PM, Richard Baskett at [EMAIL PROTECTED] wrote:

 Well I saw a post on a forum talking about a certain bug that PHP has for Mac
 OS X.. so I thought.. Im on OS X, I should see if that bug is real since on
 bugs.php.net they say it's bogus which you can view here:
 
 http://bugs.php.net/bug.php?id=25394
 
 So I tried it out.. at first I created a loop that assigned $x = 1; a whole
 bunch of times, but that didn¹t crash anything..  I then read the authors post
 a little closer and I realized it was a number of lines problem.. so I crated
 a php file that had a whole bunch of $x = 1; commands in it.. 7996 to be
 exact.. add the opening and closing php tag.. that made 7998 lines.. the
 script still worked.. Now I added one more line so that there were 7999 lines
 and guess what?  Yep you got it.. my script didn¹t work anymore.  Which the
 author it looks like it took 8014 lines instead of my 7999 lines to break it.
 
 I thought this was strange and it looked like the author of the php bug report
 was indeed on the up-and-up and it wasn¹t a bogus bug as bugs.php.net had said
 it was.
 
 So I thought to myself.. well I should post to bugs.php.net and tell them that
 I to can reproduce the bug.  So I did.
 
 Well to make an already long story short.. it looks like after a couple of
 hours bugs.php.net has removed my post.
 
 My question to you is.. is there any reason why they would remove my post? For
 me.. since I do not write that many lines of code for one run of a script it
 really didn¹t matter much to me, but since they removed my post.. it's
 beginning to make me wonder what's going on..
 
 Hopefully someone can shed some light!

Well Eugene.. it looks like your post was removed also.  We are wondering if
it is automatic when a bug is deemed bogus or if there is some other
reason.. But then again it takes awhile for it to be removed.. so if it was
a script that does it, Im not sure why it would take that long to run..

I really have no clue of what's going on.. and so far only one person on OS
X, Mr. Blanchard himself, has not had this problem.. as far as I know.  So I
don't think they would be ignoring this.. I would be curious to hear what
Rasmus had to say.. since I think he would know the innerworkings of php
plus the bugs.php.net site..

Anyways hopefully something can be figured out!

Rick

Too much caution is bad for you. By avoiding things you fear, you may let
yourself in for unhappy consequences. It is usually wiser to stand up to a
scary-seeming experience and walk right into it, risking the bruises as hard
knocks. You are likely to find it is not as tough as you had thought.  Or
you may find it plenty tough, but also discover you have what it takes to
handle it. - Norman Vincent Peale

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