[PHP] How do you declare Vars in PHP? -I know it's not necessary, but I still want to know
I just found a place here: http://us2.php.net/manual/en/language.oop.php That has this example: /* This is how it should be done. */ class Cart { var $todays_date; var $name; var $owner; var $items = array(VCR, TV); function Cart() { $this-todays_date = date(Y-m-d); $this-name = $GLOBALS['firstname']; /* etc. . . */ } } It appears that they are declaring vars like this: var $todays_date; Is this something you can only do inside a class??? -Jon Bala Chandar [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi On 5/5/05, Jon M. [EMAIL PROTECTED] wrote: I know in JavaScript, that you declare vars like so: var = variableName; So I'm assuming that in PHP you do it like this: var = $variableName; I think you can do like this inside a class var $variableName; But there doesn't seem to be a single shred of documentation on PHP.net (or in ANY book) that covers this. All they say is that it's good practice, but check out http://www.php.net/manual/en/language.variables.php not necessary. Then they always skip telling you how. I always like to declare vars since it helps me keep track of the vars I will be using, and I just like to do things right. So am I right about how you do it? Yes, No, example please?? when u use OO concepts, then you can use var. other wise its not neccessary. -Jon -- bala balachandar muruganantham blog lynx http://chandar.blogspot.com web http://www.chennaishopping.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Thanks, I understand now
OK, thanks everyone. My question has been thoroughly answered, and I completely understand now. I did try the var $varName; outside a class, just to see what happened, and found out it does indeed throw a parse error, so I'll just use a comment as suggested. I wonder why Beginning PHP 5 and MySQL from Novice to Professional by W. Jason Gilmore says to declare them? I guess he just meant by assigning a value like: $varName = Null or something. I just have to get used to this new way of declaring -lol. -Jon Rasmus Lerdorf [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Jon M. wrote: So, are you saying that it is absolutely PHP-illegal to do: Yes, it is illegal. Inside a class definition you can define properties like this, but for regular variables it is simply not supported. And it makes no sense. If you can't stop your hands from typing this stuff, do this: #var $varName; -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: How to declare Vars in PHP?
OK, thanks everyone. (BTW -I actually meant to say 'var $varName;' in PHP and 'var varName;' in JavaScript -doh!) Anyway, my question has been thoroughly answered, and I completely understand now. I did try the var $varName; outside a class, just to see what happened, and found out it does indeed throw a parse error, so I'll just use a comment as Mr. Rasmus suggested. I wonder why Beginning PHP 5 and MySQL from Novice to Professional by W. Jason Gilmore says to declare them? I guess he just meant by assigning a value like: $varName = Null or something. I just have to get used to this new way of declaring -lol. And thanks especially Ryan. That is a very informational answer, and gives me a much deeper insight into why PHP doesn't allow an actual definition, than any other resource/explanation I have ever seen! Thank you VERY much for taking the time to write that, I am the kind of person who wants to completely understand a subject (not just how, but, why as well), and now I completely understand this particular part of PHP. -Jon Ryan Faricy [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Jon M. [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I know it's not necessary, but I still want to know how. I know in JavaScript, that you declare vars like so: var = variableName; So I'm assuming that in PHP you do it like this: var = $variableName; But there doesn't seem to be a single shred of documentation on PHP.net (or in ANY book) that covers this. All they say is that it's good practice, but not necessary. Then they always skip telling you how. I always like to declare vars since it helps me keep track of the vars I will be using, and I just like to do things right. So am I right about how you do it? Yes, No, example please?? -Jon It is good practice to define your variables (i.e., set them to 0, or empty, etc) at the beginning of a script, for security and reliability reasons. With PHP however, there technically is no definition of variables as in other languages such as Java or BASIC. To define a variable in PHP simply requires a $variableName = ''; or $variableName = 0; or $variableName = empty; etc etc. A variable is defined as soon as a value is set for it, therefore to define a variable, simply give it a value. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[suspicious - maybe spam] [PHP] Simple question: How to declare Vars in PHP? (I know it's not necessary, but I still want to know)
I know in JavaScript, that you declare vars like so: var = variableName; So I'm assuming that in PHP you do it like this: var = $variableName; But there doesn't seem to be a single shred of documentation on PHP.net (or in ANY book) that covers this. All they say is that it's good practice, but not necessary. Then they always skip telling you how. I always like to declare vars since it helps me keep track of the vars I will be using, and I just like to do things right. So am I right about how you do it? Yes, No, example please?? -Jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[suspicious - maybe spam] [PHP] How to declare Vars in PHP?
I know it's not necessary, but I still want to know how. I know in JavaScript, that you declare vars like so: var = variableName; So I'm assuming that in PHP you do it like this: var = $variableName; But there doesn't seem to be a single shred of documentation on PHP.net (or in ANY book) that covers this. All they say is that it's good practice, but not necessary. Then they always skip telling you how. I always like to declare vars since it helps me keep track of the vars I will be using, and I just like to do things right. So am I right about how you do it? Yes, No, example please?? -Jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [suspicious - maybe spam] Re: [suspicious - maybe spam] [PHP] Simple question: How to declareVars in PHP? (I know it's not necessary, but I still want to know)
Oops!! What I meant was: JavaScript: var varName; PHP: var $varName; I can't believe I did that (I have been writing JavaScript for a few years, and know better -I gotta get more sleep). So, are you saying that it is absolutely PHP-illegal to do: var $varName; in PHP??? Would it be ignored? Or would it screw up the interpreter? Rasmus Lerdorf [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Jon M. wrote: I know in JavaScript, that you declare vars like so: var = variableName; So I'm assuming that in PHP you do it like this: var = $variableName; But there doesn't seem to be a single shred of documentation on PHP.net (or in ANY book) that covers this. All they say is that it's good practice, but not necessary. Then they always skip telling you how. I always like to declare vars since it helps me keep track of the vars I will be using, and I just like to do things right. So am I right about how you do it? Yes, No, example please?? No You don't declare variables in PHP. You just start using them. Perhaps you mean assign? Since your example of var = variableName; is actually an assignment in Javascript. In PHP you simply do: $one_var = $another_var; -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is it possible to save a file with UTF-8 encoding and noBOMusing PHP?
(Rasmus wrote:) If you fwrite UTF-8 data to the file, then it is a UTF-8 file. Thanks Rasmus! Honestly, that is REALLY helpful! I was just coming back here to post that I had found that very same answer. But I am glad to hear it confirmed by the experts. Bottom line: I was just being silly/ignorant. I went and downloaded a simple HEX editor and compared the actual binary output of several files that I had created using both PHP, and my favorite text editor (emeditor from emeditor.com). I then realized what probably everyone else here already knew: that (most of the time) the actual binary output from Windows 1252 and ISO-8859-1 and UTF-8 without the byte order mark -are completely identical! I had the false impression that when a file was saved in UTF-8, that there was an actual binary marker that specified this (e.g. binary marker = This file is saved in UTF-8!) -there simply is no such thing. The only thing that would set UTF-8 apart -binarilly speaking- is the BOM, and I had stripped that out, making the file exactly the same as plain old ANSI (since I didn't have any characters that required UTF-8, like from other languages etc.). My text editor displays the current character encoding in the status bar, but since there was no way for it to tell whether it was saved with Windows 1252 or UTF-8, it just displayed that the file was encoded windows default - ISO-8859-1. This is where I got confused. It turned out that my PHP script has been faithfully saving the file in UTF-8 the whole time, and everything was fine. I was just not educated enough about what actually changed when you save a file in UTF-8 but didn't have any characters that differed from ANSI (which in my case, the change was nothing, since ALL of the characters in my test document where interchangeable with ANSI). Well, this has been a learning experience! I hope that this post will help some poor ignoramus like myself, sometime in the future! :) And hopefully I am right about what I said above, and not flaunting my ignorance once again -lol Thanks again, to everyone who helped me! You guys really got me on the right track. Not the least of which was simply causing me to think about what I was asking more deeply. -Jon Rasmus Lerdorf [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Jon M. wrote: No matter what I do to the strings to encode them in whatever format before using fwrite, it ALWAYS seems to end up writing the actual file in iso-8859-1. Isn't the encoding of the characters in PHP's strings, and the encoding of the actual binary file on your hard drive, two totally different things? Or am I just misinformed? A file is completely defined by its contents. If you fwrite UTF-8 data to the file, then it is a UTF-8 file. Whether your editor, or whatever it is you are using to determine the file is being written as iso-8859-1 is smart enough to pick this up is a completely different question. Why don't you try creating the same contents with PHP and with your preferred text editor and then compare the contents. Perhaps your editor is dropping a hint somewhere in it that you are not writing to the file from PHP. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is it possible to save a file with UTF-8 encoding and noBOM using PHP?
Thanks also, Richard! You were right on. Just a note: I just visited the W3C validation service again, and it seems they have recently updated it. It no longer complains if it finds a BOM in your document binary. So it would appear that it's no longer an issue with enough XML parsers to be relevant anymore. Still, it is nice to have a program -like I do- that has that flexibility. -Jon Richard Lynch [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Thu, April 28, 2005 4:14 am, Jon M. said: No matter what I do to the strings to encode them in whatever format before using fwrite, it ALWAYS seems to end up writing the actual file in iso-8859-1. How do you know? What are you using to determine the format of the file? We are contending that either you are *not* writing UTF-8 data, but are writing iso-8859-1 data, or the software telling you that it's not UTF-8 is just plain *wrong* fwrite just takes your data and dumps it on the hard drive. It doesn't know UTF-8 from U2. Isn't the encoding of the characters in PHP's strings, and the encoding of the actual binary file on your hard drive, two totally different things? Or am I just misinformed? You are mis-informed. How do you actually control the way the binary file itself is written, and not just the text that is saved in the file? If you are using Windows, then *WINDOWS* is, perhaps, guessing on the binary format based on the file 'extension' (.txt) and on the contents. First, try renaming the file to, err, whatever Windows thinks UTF-8 file extensions should be... .utf8 ??? Whatever Notepad uses. Next, forget what Windows desktop tells you. It's bull. When you get the data back out of the file, what format is it? PS You may be confusing Windows by writing UTF-8 without the BOM, and so Windows then thinksit's iso-8859-1, because it's no longer a valid UTF-8 file! You can make Windows happy; or you can make W3c happy. Not both. -- 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] Is it possible to save a file with UTF-8 encoding and noBOM using PHP?
Wow, nice to hear from the guy who created PHP! :) I need to make 2 things clearer though: 1. First I want to know how to make the actual binary file that is written, to be encoded as UTF-8. This is my PRIMARY question. 2. How to have fwrite write the file without the BOM. (to make it more compatible with certain XML parsers -per the W3C's recommendation). No matter what I do to the strings to encode them in whatever format before using fwrite, it ALWAYS seems to end up writing the actual file in iso-8859-1. Isn't the encoding of the characters in PHP's strings, and the encoding of the actual binary file on your hard drive, two totally different things? Or am I just misinformed? Example: When I open up Windows Notepad, then I type some stuff into it, and then I choose file, save as, encoding: UTF-8, then I click save. So how do I do this SAME thing using PHP? Could someone give me a actual code example of how to do that? I'm just s lost. How do you actually control the way the binary file itself is written, and not just the text that is saved in the file? Rasmus Lerdorf [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Jon M. wrote: Richard Lynch [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Thu, April 21, 2005 5:07 pm, Jon M. said: I am trying to have a file that I generated with PHP saved as UTF-8 without the BOM (Byte Order Mark). Does PHP do anything like this? I am a beginner with PHP, but very technically experienced otherwise. I'm talking about the FILE encoding here -just to be clear. e.g. fopen(what_ever_file, a+) now I want PHP save the file itself with UTF-8, NOT system default. I have searched for hours to find an answer, but have not found any info on the subject. Does PHP have any ability to create a text file saved in UTF-8 encoding??? Maybe I'm just being dumb, but I think if you UTF-8 encode your data, and http://php.net/fwrite it, you're gonna get what you want... Dunno about the Byte-Order-Mark part, but I guess you could strip it out of the UTF-8 encoded data before writing, if you wanted to. -- Like Music? http://l-i-e.com/artists.htm That was the first thing I tried, and it doesn't seem to work (it always saves in windows default encoding). Unless I missing something about what you can do with fwrite. Did you actually test that before you replied, and found that it would? If so, how? The Byte Order Mark is a part of the binary file that is written, how would one go about stripping it out?? BTW, note to PHP developers: If fwrite had a encoding parameter, e.g. UTF-8, that would be REALLY handy. Strings in PHP are binary-safe and character-encoding neutral. fwrite doesn't have a clue what it is writing, it just writes what is in memory. I'd question why you would want to strip the BOM. Any modern system deals with the byte-order-mark correctly. But you can simply strip it manually if it is present in the first 2 bytes before your fwrite if you really need to get rid of it. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is it possible to save a file with UTF-8 encoding and no BOM using PHP?
Richard Lynch [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Thu, April 21, 2005 5:07 pm, Jon M. said: I am trying to have a file that I generated with PHP saved as UTF-8 without the BOM (Byte Order Mark). Does PHP do anything like this? I am a beginner with PHP, but very technically experienced otherwise. I'm talking about the FILE encoding here -just to be clear. e.g. fopen(what_ever_file, a+) now I want PHP save the file itself with UTF-8, NOT system default. I have searched for hours to find an answer, but have not found any info on the subject. Does PHP have any ability to create a text file saved in UTF-8 encoding??? Maybe I'm just being dumb, but I think if you UTF-8 encode your data, and http://php.net/fwrite it, you're gonna get what you want... Dunno about the Byte-Order-Mark part, but I guess you could strip it out of the UTF-8 encoded data before writing, if you wanted to. -- Like Music? http://l-i-e.com/artists.htm That was the first thing I tried, and it doesn't seem to work (it always saves in windows default encoding). Unless I missing something about what you can do with fwrite. Did you actually test that before you replied, and found that it would? If so, how? The Byte Order Mark is a part of the binary file that is written, how would one go about stripping it out?? BTW, note to PHP developers: If fwrite had a encoding parameter, e.g. UTF-8, that would be REALLY handy. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] How to save a file with UTF-8 encoding and no BOM using PHP?
I am trying to have a file that I generated with PHP saved as UTF-8 without the BOM (Byte Order Mark). Does PHP do anything like this? I am a beginner with PHP, but very technically experienced otherwise. I'm talking about the FILE encoding here -just to be clear. e.g. fopen(what_ever_file, a+) now I want PHP save the file itself with UTF-8, NOT system default. I have searched for hours to find an answer, but have not found any info on the subject. Does PHP have any ability to create a text file saved in UTF-8 encoding??
[PHP] How to save a file with UTF-8 encoding and no BOM using PHP?
I am trying to have a file that I generated with PHP saved as UTF-8 without the BOM (Byte Order Mark). Does PHP do anything like this? I am a beginner with PHP, but very technically experienced otherwise. I'm talking about the FILE encoding here -just to be clear. e.g. fopen(what_ever_file, a+) now I want PHP save the file itself with UTF-8 encoding, NOT system default. I have searched for hours to find an answer, but have not found any info on the subject. Does PHP have any ability to create a text file saved in UTF-8 encoding?? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Is it possible to save a file with UTF-8 encoding and no BOM using PHP?
I am trying to have a file that I generated with PHP saved as UTF-8 without the BOM (Byte Order Mark). Does PHP do anything like this? I am a beginner with PHP, but very technically experienced otherwise. I'm talking about the FILE encoding here -just to be clear. e.g. fopen(what_ever_file, a+) now I want PHP save the file itself with UTF-8, NOT system default. I have searched for hours to find an answer, but have not found any info on the subject. Does PHP have any ability to create a text file saved in UTF-8 encoding??? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php