note 89757 added to language.types.string
| From: | Jarobman at osu1 dot php dot net | Date: | Sat, 21 Mar 2009 21:20:14 +0000 |
| Subject: | note 89757 added to language.types.string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152267@lists.php.net to get a copy of this message | ||
One thing I have noticed (using PHP 5.2.4) is that alphanumeric text starting with letters or
underscore without spaces and operators in PHP code without single or double quotes is interpreted
as a string. I noticed this when trying to access a member variable from an object and getting an
integer returned on what I thought should have been a syntax error. The text cannot correspond to
most PHP keywords since that would generate a fatal error.
<?php
class MyObject
{
private $__internal_array = array();
//insert code for overloading __get(), __set(), etc. to
//access items from $__internal_array
}
$object = new MyObject();
//thought this would give a syntax error, put param returned an int somehow
some_function($object-membervar);
//correct
echo hiImAString;
//correct
echo hello.world._6789;
//correct
thisisastandalonestring;
//correct, outputs 0
echo string+anotherstring-yetanotherstring;
//correct, outputs 1concatenated
echo true.false.concatenated;
//incorrect, syntax error
echo cantdothis.1234567890;
//incorrect, syntax error, use of PHP keywords
echo try.and.do.this.if.you.can.else.break;
?>
Any other combination of the above with operators and other special characters will generate fatal
errors. I think it would be the opinion of many people that this form of a string is not at all
practical and should never be used at all. Personally, I think this looks like a bug, but I could
be wrong. However, this is something else one could watch out for when debugging since this is hard
to pick up in code especially when expecting integer or boolean values.
Cheers,
Jarobman
----
Server IP: 66.207.199.35
Probable Submitter: 74.216.0.200
----
Manual Page -- http://www.php.net/manual/en/language.types.string.php
Edit -- https://master.php.net/note/edit/89757
Del: integrated -- https://master.php.net/note/delete/89757/integrated
Del: useless -- https://master.php.net/note/delete/89757/useless
Del: bad code -- https://master.php.net/note/delete/89757/bad+code
Del: spam -- https://master.php.net/note/delete/89757/spam
Del: non-english -- https://master.php.net/note/delete/89757/non-english
Del: in docs -- https://master.php.net/note/delete/89757/in+docs
Del: other reasons-- https://master.php.net/note/delete/89757
Reject -- https://master.php.net/note/reject/89757
Search -- https://master.php.net/manage/user-notes.php