[PHP-DEV] Bug #15368 Updated: Should document {}, [], ->, and & in Operators section of the manual

2002-02-07 Thread hek

 ID:   15368
 Updated by:   [EMAIL PROTECTED]
-Reported By:  [EMAIL PROTECTED]
+Reported By:  [EMAIL PROTECTED]
 Status:   Open
 Bug Type: Documentation problem
 Operating System: N/A
 PHP Version:  4.1.1
 New Comment:

This is substantially the same as Bug#9983.


Previous Comments:


[2002-02-04 11:14:47] [EMAIL PROTECTED]

The operators seciot of the online PHP Manual omits mention of:

  {} -- used to extarct a particular character from a string (with an
aside about using {} to embed variable values in strings);

  [] -- the array subscriptor (which is actually listed inthe operator
precedence table, though mentioned nowhere else);

  -> -- the object property/method accessor;

  & -- the reference operator (also listed in the precendence table,
though never explained elsewhere);

  => -- the array key-to-value keyword (not techniclly an operator, I
know, but because it's so "punctuation-y", probably a good thing to
comment on in this section).

Also, the operators precendence table at
http://www.php.net/manual/en/language.operators.precedence.php should
probably hyperlink each operator to the appropriate page describing
it.

And finally, it might make more sense to put the operator precendence
information (including the new and improved table with hyperlinks)
right on the first page of the operators section (rather than the
arithmentic operators information).




-- 
Edit this bug report at http://bugs.php.net/?id=15368&edit=1


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




[PHP-DEV] Bug #9983 Updated: Operator Precedence Clarification/Additions

2002-02-07 Thread hek

 ID:   9983
 Updated by:   [EMAIL PROTECTED]
-Reported By:  [EMAIL PROTECTED]
+Reported By:  [EMAIL PROTECTED]
 Status:   Open
 Bug Type: Documentation problem
 Operating System: Linux/W2K
 PHP Version:  4.0.4pl1
 New Comment:

This is substantially the same as Bug#15368.


Previous Comments:


[2001-06-27 03:37:24] [EMAIL PROTECTED]

This is a suggestion for improving the manual.
(I don't mind at all if you close this :)

Reference is for PHP programmers, so I think precidence section is
better to include more operators.

For example, it does not matter if unary '+/-', array '[]', member
selecter '->', etc are treated by parser or internal function for
programmers. Programmers don't cares about it when they are programming
in some language, right?

Important thing for programmers is the precedence itself in some
expression. 
How about add more description for precedence just like other books or
references for programming languages? 

I feel precedence is not described fully in current manual and it's
worth the effort.

Another Releated Suggestion
I see confusion occasionally in mail lists for variables in string.
Since parser behaives differently when parsing variables in strings.

This may be one of the reason why '->','[]',unary'+/-' is not in the
precedence section. They wouldn't work when they are in a string. (Some
of them work with newer PHP, not recommended(?) syntax, though)

How about describe these differences in the manual also? 




[2001-06-27 01:49:36] [EMAIL PROTECTED]

Changing description to be more meaningful for someone who wants to
tackle this.



[2001-03-26 05:10:50] [EMAIL PROTECTED]

I read precedence list again. There is "." operator listed and has
higher precedence than "?:" operator. So PHP is working as expected. I
didn't see "." It was hard to see on my browser. Thanks.

Anyway, I have suggestion for the manual page, so I changed status to
open as "Documentation Problem".

I think the manual page better to have relevant language constructs in
the precedence list even if it is not a actually a operator in PHP.
(Such as "()", "{}", "::", "->", unary "-","+". It seems these are not
a operator in PHP, since they are not listed. Not sure though.) Only
"()" is described in the section. All of them affects how expressions
are evaluated in script and I think precedence for these is important
as operator precedence because programmers want expressions are
evaluated as expected. 

How about change the section title from "Operator Precedence" to
"Precedence"? Then documentation can include anything that can affects
expression and still have consistency with section title.

It also would be nice to have a little explaination for each operator
in the precedence list. Since it is ambigous if listed operator is
unary or binary. For example, unary "-" should have higher precedence
than binary "-". It would be obvious for most users, but it may be
usuful for someone.




[2001-03-26 03:46:52] [EMAIL PROTECTED]

Please read this manual page:

http://www.php.net/manual/en/language.operators.precedence.php

--Jani




[2001-03-26 00:17:05] [EMAIL PROTECTED]

Following code, needs "()" to get expected value. 

$bar = true; 
$str = "TEST". ($bar ? 'true' : 'false') ."TEST"; 

Without "(" and ")", only "true" will be in $str. 
(PHP4.0.4pl1/Apache DSO/Linux, PHP4.0.5RC1/Apache DSO/W2K Server) 
If this is expected behavior in PHP, it would better to be described in
the Manual.





-- 
Edit this bug report at http://bugs.php.net/?id=9983&edit=1


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




[PHP-DEV] Bug #15330 Updated: An efficient way to access the last element of an array is sorely missed

2002-02-07 Thread hek

 ID:   15330
 Updated by:   [EMAIL PROTECTED]
-Reported By:  [EMAIL PROTECTED]
+Reported By:  [EMAIL PROTECTED]
 Status:   Bogus
 Bug Type: Feature/Change Request
 Operating System: N/A
 PHP Version:  4.1.1
 New Comment:

Did I already reply to this?  Please accept my apologies if I did, and
have just misplaced the reply.

Thank you for the suggested code.

Turns out that all along end() does exactly what I've wanted -- I just
didn't catch the part at the end of the manual page for it, where it
says the return value is the value of the last element in the array.  I
think I was misled by [EMAIL PROTECTED]'s line:

>> end --  Set the internal pointer of an array to its last element.

Sorry for all the bother I've been.  Still think that the functions I
suggested would do no harm in the library, espescially as then they
could be even more efficient than if implemented as user functions.

But thanks again.

--Haig


Previous Comments:


[2002-02-04 16:15:43] [EMAIL PROTECTED]

Well, if you wouldn't worry about using the internal 
pointers, you'd have an easier time of this. :) You can
do what you need very trivially (note that I'm not saying
these functions shouldn't be added to PHP, just that this
is already easy to do in userland):

For instance:

function array_first_key($array) {
reset($array);
return key($array);
}

function array_last_key($array) {
end($array);
return key($array);
}

...for the *_value() versions, use current() instead of
key(). For the index searcher, you can do something like:


function array_element_key($array, $element) {
if (abs($element) > count($array)) {
return false;
}

if ($element < 0) {
for ($i = -1, end($array); $i > $element; $i--, prev($array));
} else {
for ($i = 0, reset($array); $i < $element; $i++,
next($array));
}

return key($array);
}

...and so on.


Hope this helps until (if) these get added to the language.
Email me privately if you want the whole batch of 
functions.


Torben



[2002-02-04 10:30:39] [EMAIL PROTECTED]

Aha!  Now I see array_slice() -- much closer to that I was proposing. 
However, it still does not get you the value you are after directly,
but an array (sans original keys) you then have to delve into for your
value.  Still, closer.

Also, I've found the well-hidden information on getting a CVS account,
so no need for that pointer now.  Thanks again.

--HaigEK



[2002-02-04 10:03:15] [EMAIL PROTECTED]

Yes, I am aware of end().  It certainly has a purpose and a use, but it
isn't at all the same as what I was suggesting.

Frankly, I never use the "internal pointer" features of arrays, as they
were at first alien to me, and later seemed unreliable when I thought I
understood them.

Providing altenative methods for ding things in  programming language
as otherwise accomodating as PHP, seems to me, precisely in character
with its philosophy.

I would be more than happy to contribute these functions myself, if
someone will point me in the right direction to do so.  Thank you.

--HaigEK



[2002-02-01 15:11:56] [EMAIL PROTECTED]

These functions have been available for a long time and are
well documented in the manual--see the previous comment.


Torben



[2002-02-01 14:38:56] [EMAIL PROTECTED]

While there is no way to set the internal pointer (afaik) to a given
element #, you can set the pointer to the first/last/next/previous
item.

http://se.php.net/manual/en/function.end.php

end --  Set the internal pointer of an array to its last element.

--
mats



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/15330

-- 
Edit this bug report at http://bugs.php.net/?id=15330&edit=1


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




[PHP-DEV] Bug #15368: Should document {}, [], ->, and & in Operators section of the manual

2002-02-04 Thread hek

From: [EMAIL PROTECTED]
Operating system: N/A
PHP version:  4.1.1
PHP Bug Type: Documentation problem
Bug description:  Should document {}, [], ->, and & in Operators section of the manual

The operators seciot of the online PHP Manual omits mention of:

  {} -- used to extarct a particular character from a string (with an
aside about using {} to embed variable values in strings);

  [] -- the array subscriptor (which is actually listed inthe operator
precedence table, though mentioned nowhere else);

  -> -- the object property/method accessor;

  & -- the reference operator (also listed in the precendence table,
though never explained elsewhere);

  => -- the array key-to-value keyword (not techniclly an operator, I
know, but because it's so "punctuation-y", probably a good thing to
comment on in this section).

Also, the operators precendence table at
http://www.php.net/manual/en/language.operators.precedence.php should
probably hyperlink each operator to the appropriate page describing it.

And finally, it might make more sense to put the operator precendence
information (including the new and improved table with hyperlinks) right
on the first page of the operators section (rather than the arithmentic
operators information).
-- 
Edit bug report at http://bugs.php.net/?id=15368&edit=1
-- 
Fixed in CVS:http://bugs.php.net/fix.php?id=15368&r=fixedcvs
Fixed in release:http://bugs.php.net/fix.php?id=15368&r=alreadyfixed
Need backtrace:  http://bugs.php.net/fix.php?id=15368&r=needtrace
Try newer version:   http://bugs.php.net/fix.php?id=15368&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=15368&r=support
Expected behavior:   http://bugs.php.net/fix.php?id=15368&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=15368&r=notenoughinfo


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




[PHP-DEV] Bug #15329 Updated: Subscripting into strings would be useful

2002-02-04 Thread hek

 ID:   15329
 Updated by:   [EMAIL PROTECTED]
 Reported By:  [EMAIL PROTECTED]
 Status:   Bogus
 Bug Type: Feature/Change Request
 Operating System: N/A
 PHP Version:  4.1.1
 New Comment:

Ooops.  Getting confused about my posts (arrays versus strings).

OK, I've found the very brief comments on "String access by character"
-- that is, using {} to reference characters within strings --
documented near the end of
http://www.php.net/manual/en/language.types.string.php in the PHP
Manual.

As described this gets the caller a single charecter.  A nice
enhancement would be to let the syntax also support ranges, by
accomodating an optional second argument, length.  Examples:

$string = "abcde";
echo $string{1,3}; // To get "bcd" -- offset 1, length 3

But then you'd have to think about how to handle negative values, blah,
blah, blah.

I know, I know...  You're going to bogus this because it's not likely
to ever get implemented.  Never mind.

You might think about listing the {} operators (and the [], ->, and &
operators, too) in the operators section of the manual, however, to
make it easier for people to find out about them in the future.

--HaigEK


Previous Comments:


[2002-02-04 10:16:18] [EMAIL PROTECTED]

Thank you.  I know about substr() -- which is rather cumbersome
compared with the notation I suggested -- but I don't know what you
mean by {}.

I cannot find this notation explainined in the PHP Manual (at least not
in the pages about array functions, about the array type, nor in the
pages about operators).

Where is {} usage described?

--HaigEK



[2002-02-01 14:50:01] [EMAIL PROTECTED]

Already supported by {} and substr.

Derick



[2002-02-01 13:48:17] [EMAIL PROTECTED]

The now very old North Star BASIC had a wonderful feature that I'd love
to see in PHP, which was the ability to access strings using
subscripts, rather like subscripting into an array, except even better
since it allowed ranges to be subscripted just as easily as single
characters in the strings.

Examples:

$string = "My String";

echo $string[5]; // returns "r"
echo $string[0,]; // returns "My String"
echo $string[3,5]; // returns "Str"
echo $string[,3]; // returns "My S"




-- 
Edit this bug report at http://bugs.php.net/?id=15329&edit=1


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




[PHP-DEV] Bug #15330 Updated: An efficient way to access the last element of an array is sorely missed

2002-02-04 Thread hek

 ID:   15330
 Updated by:   [EMAIL PROTECTED]
 Reported By:  [EMAIL PROTECTED]
 Status:   Bogus
 Bug Type: Feature/Change Request
 Operating System: N/A
 PHP Version:  4.1.1
 New Comment:

Aha!  Now I see array_slice() -- much closer to that I was proposing. 
However, it still does not get you the value you are after directly,
but an array (sans original keys) you then have to delve into for your
value.  Still, closer.

Also, I've found the well-hidden information on getting a CVS account,
so no need for that pointer now.  Thanks again.

--HaigEK


Previous Comments:


[2002-02-04 10:03:15] [EMAIL PROTECTED]

Yes, I am aware of end().  It certainly has a purpose and a use, but it
isn't at all the same as what I was suggesting.

Frankly, I never use the "internal pointer" features of arrays, as they
were at first alien to me, and later seemed unreliable when I thought I
understood them.

Providing altenative methods for ding things in  programming language
as otherwise accomodating as PHP, seems to me, precisely in character
with its philosophy.

I would be more than happy to contribute these functions myself, if
someone will point me in the right direction to do so.  Thank you.

--HaigEK



[2002-02-01 15:11:56] [EMAIL PROTECTED]

These functions have been available for a long time and are
well documented in the manual--see the previous comment.


Torben



[2002-02-01 14:38:56] [EMAIL PROTECTED]

While there is no way to set the internal pointer (afaik) to a given
element #, you can set the pointer to the first/last/next/previous
item.

http://se.php.net/manual/en/function.end.php

end --  Set the internal pointer of an array to its last element.

--
mats



[2002-02-01 14:07:08] [EMAIL PROTECTED]

There seems to be no easy and efficient way to access the last element
of an array (assuming you don't already know the key to that element). 
The most concise, though not terribly efficient workaround I have
discovered is...

   $array[array_pop(array_keys($array))]

...which first extracts all the keys of the array, then pops off the
last key and uses it as an index into the array.  Fairly easy to write
and understand (though bulky), but horribly inefficient.

Perhaps there is a place for new array_lastkey($array),
array_firstkey($array), and array_element_key($array, $n) functions. 
The first of these functions would simply return the last key in the
array (or null if the array is empty).  The second would return the
first key in the array (or null). In the third, $n would be a numeric
index into the array, totally unrelated to the array's keys.  A
positive number would indicate how far "into" the array to go, a
negative number would indicate how far "backward" into the array to go,
while 0 or an out of bounds index might either quietly return a null or
might throw an error or warning.

Some Examples:

$array = array( 1 => "One", "two" => "Two", -3 => "Minus Three" );

echo $array[array_firstkey($array)]; // returns "One" because
array_firstkey() returns 1

echo $array[array_lastkey($array)]; // returns "Minus Three" because
array_lastkey() returns -3

echo $array[array_element_key($array,1)]; // returns "One" because
array_element_key() returns 1
echo $array[array_element_key($array,2)]; // returns "Two" because
array_element_key() returns "two"
echo $array[array_element_key($array,-2)]; // returns "Two" because
array_element_key() returns "two"
echo $array[array_element_key($array,-1)]; // returns "Minus Three"
because array_element_key() returns -3





-- 
Edit this bug report at http://bugs.php.net/?id=15330&edit=1


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




[PHP-DEV] Bug #15329 Updated: Subscripting into strings would be useful

2002-02-04 Thread hek

 ID:   15329
 Updated by:   [EMAIL PROTECTED]
 Reported By:  [EMAIL PROTECTED]
 Status:   Bogus
 Bug Type: Feature/Change Request
 Operating System: N/A
 PHP Version:  4.1.1
 New Comment:

Thank you.  I know about substr() -- which is rather cumbersome
compared with the notation I suggested -- but I don't know what you
mean by {}.

I cannot find this notation explainined in the PHP Manual (at least not
in the pages about array functions, about the array type, nor in the
pages about operators).

Where is {} usage described?

--HaigEK


Previous Comments:


[2002-02-01 14:50:01] [EMAIL PROTECTED]

Already supported by {} and substr.

Derick



[2002-02-01 13:48:17] [EMAIL PROTECTED]

The now very old North Star BASIC had a wonderful feature that I'd love
to see in PHP, which was the ability to access strings using
subscripts, rather like subscripting into an array, except even better
since it allowed ranges to be subscripted just as easily as single
characters in the strings.

Examples:

$string = "My String";

echo $string[5]; // returns "r"
echo $string[0,]; // returns "My String"
echo $string[3,5]; // returns "Str"
echo $string[,3]; // returns "My S"




-- 
Edit this bug report at http://bugs.php.net/?id=15329&edit=1


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




[PHP-DEV] Bug #15330 Updated: An efficient way to access the last element of an array is sorely missed

2002-02-04 Thread hek

 ID:   15330
 Updated by:   [EMAIL PROTECTED]
 Reported By:  [EMAIL PROTECTED]
 Status:   Bogus
 Bug Type: Feature/Change Request
 Operating System: N/A
 PHP Version:  4.1.1
 New Comment:

Yes, I am aware of end().  It certainly has a purpose and a use, but it
isn't at all the same as what I was suggesting.

Frankly, I never use the "internal pointer" features of arrays, as they
were at first alien to me, and later seemed unreliable when I thought I
understood them.

Providing altenative methods for ding things in  programming language
as otherwise accomodating as PHP, seems to me, precisely in character
with its philosophy.

I would be more than happy to contribute these functions myself, if
someone will point me in the right direction to do so.  Thank you.

--HaigEK


Previous Comments:


[2002-02-01 15:11:56] [EMAIL PROTECTED]

These functions have been available for a long time and are
well documented in the manual--see the previous comment.


Torben



[2002-02-01 14:38:56] [EMAIL PROTECTED]

While there is no way to set the internal pointer (afaik) to a given
element #, you can set the pointer to the first/last/next/previous
item.

http://se.php.net/manual/en/function.end.php

end --  Set the internal pointer of an array to its last element.

--
mats



[2002-02-01 14:07:08] [EMAIL PROTECTED]

There seems to be no easy and efficient way to access the last element
of an array (assuming you don't already know the key to that element). 
The most concise, though not terribly efficient workaround I have
discovered is...

   $array[array_pop(array_keys($array))]

...which first extracts all the keys of the array, then pops off the
last key and uses it as an index into the array.  Fairly easy to write
and understand (though bulky), but horribly inefficient.

Perhaps there is a place for new array_lastkey($array),
array_firstkey($array), and array_element_key($array, $n) functions. 
The first of these functions would simply return the last key in the
array (or null if the array is empty).  The second would return the
first key in the array (or null). In the third, $n would be a numeric
index into the array, totally unrelated to the array's keys.  A
positive number would indicate how far "into" the array to go, a
negative number would indicate how far "backward" into the array to go,
while 0 or an out of bounds index might either quietly return a null or
might throw an error or warning.

Some Examples:

$array = array( 1 => "One", "two" => "Two", -3 => "Minus Three" );

echo $array[array_firstkey($array)]; // returns "One" because
array_firstkey() returns 1

echo $array[array_lastkey($array)]; // returns "Minus Three" because
array_lastkey() returns -3

echo $array[array_element_key($array,1)]; // returns "One" because
array_element_key() returns 1
echo $array[array_element_key($array,2)]; // returns "Two" because
array_element_key() returns "two"
echo $array[array_element_key($array,-2)]; // returns "Two" because
array_element_key() returns "two"
echo $array[array_element_key($array,-1)]; // returns "Minus Three"
because array_element_key() returns -3





-- 
Edit this bug report at http://bugs.php.net/?id=15330&edit=1


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




[PHP-DEV] Bug #15330: An efficient way to access the last element of an array is sorely missed

2002-02-01 Thread hek

From: [EMAIL PROTECTED]
Operating system: N/A
PHP version:  4.1.1
PHP Bug Type: Feature/Change Request
Bug description:  An efficient way to access the last element of an array is sorely 
missed

There seems to be no easy and efficient way to access the last element of
an array (assuming you don't already know the key to that element).  The
most concise, though not terribly efficient workaround I have discovered
is...

   $array[array_pop(array_keys($array))]

...which first extracts all the keys of the array, then pops off the last
key and uses it as an index into the array.  Fairly easy to write and
understand (though bulky), but horribly inefficient.

Perhaps there is a place for new array_lastkey($array),
array_firstkey($array), and array_element_key($array, $n) functions.  The
first of these functions would simply return the last key in the array (or
null if the array is empty).  The second would return the first key in the
array (or null). In the third, $n would be a numeric index into the array,
totally unrelated to the array's keys.  A positive number would indicate
how far "into" the array to go, a negative number would indicate how far
"backward" into the array to go, while 0 or an out of bounds index might
either quietly return a null or might throw an error or warning.

Some Examples:

$array = array( 1 => "One", "two" => "Two", -3 => "Minus Three" );

echo $array[array_firstkey($array)]; // returns "One" because
array_firstkey() returns 1

echo $array[array_lastkey($array)]; // returns "Minus Three" because
array_lastkey() returns -3

echo $array[array_element_key($array,1)]; // returns "One" because
array_element_key() returns 1
echo $array[array_element_key($array,2)]; // returns "Two" because
array_element_key() returns "two"
echo $array[array_element_key($array,-2)]; // returns "Two" because
array_element_key() returns "two"
echo $array[array_element_key($array,-1)]; // returns "Minus Three"
because array_element_key() returns -3

-- 
Edit bug report at: http://bugs.php.net/?id=15330&edit=1


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] Bug #15329: Subscripting into strings would be useful

2002-02-01 Thread hek

From: [EMAIL PROTECTED]
Operating system: N/A
PHP version:  4.1.1
PHP Bug Type: Feature/Change Request
Bug description:  Subscripting into strings would be useful

The now very old North Star BASIC had a wonderful feature that I'd love to
see in PHP, which was the ability to access strings using subscripts,
rather like subscripting into an array, except even better since it
allowed ranges to be subscripted just as easily as single characters in
the strings.

Examples:

$string = "My String";

echo $string[5]; // returns "r"
echo $string[0,]; // returns "My String"
echo $string[3,5]; // returns "Str"
echo $string[,3]; // returns "My S"
-- 
Edit bug report at: http://bugs.php.net/?id=15329&edit=1


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] Bug #15328: A C-like comma operator would be useful

2002-02-01 Thread hek

From: [EMAIL PROTECTED]
Operating system: N/A
PHP version:  4.1.1
PHP Bug Type: Feature/Change Request
Bug description:  A C-like comma operator would be useful

A C-like comma operator would be useful, to string together series of
statements.

Example:

echo ($precondition
  ? ( doThisAndDiscardReturnValue(),
andDoThisAndReturnReturnValue() )
  : doSomethingElseAndReturnReturnValue() );
-- 
Edit bug report at: http://bugs.php.net/?id=15328&edit=1


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]