V1 0.4 php null
You should uses this function instead. Prefix can be useful, for instance, if you generate identifiers simultaneously on several hosts that might happen to generate the identifier at the same microsecond.
I use this function to generate microsoft-compatible GUID's. This may not be the best way to give this param variables, but it at least makes it work what appears to be properly generating unique ID's. Here is my approach to generate short string unique id. I am just increasing base of UUID.
I'm not sure the previous function by mimec is really all that random. For one thing, generating 8 small random 4 digit sequeces! Most of these notes are grossly wrong. First: you probably shouldn't be using uniqid at all. I can't think of a good reason to use it.
Maybe to use as an identifier for a particular run of your script in logging, where you don't particularly care if there's a collision?
I don't know. Second: don't rely on the output of uniqid to be, in any way, unique. This will break if you use it twice in quick succession, or if you have two different users at the same time, or if the phase of the moon is wrong. Third: to nodkz who wrote the clientIPToHex function - you reinvented so many wheels. Fourth: do not use random bytes for a unique identifier like hackan suggests. That only serves to virtually guarantee that you will eventually have a collision.
You can use random bytes, and get another set of random bytes if there's a collision I have been using mimecs version lately and do not think it's safe to think the results are always unqiue. Although it could be just my bad programming, I found exactly 1 collission while debugging my code. It seems to me that if my code was incorrect it would have happened more than once. I recommend anyone to include time as a factor of such an ID as to be a little more certain it is in fact unique. But try not to use mix and match bools with your data in your routines and you should be perfectly fine.
NULL essentially means a variable has no value assigned to it; false is a valid Boolean value, 0 is a valid integer value, and PHP has some fairly ugly conversions between 0 , "0" , "" , and false.
Not a PHP expert, but in some of the more modern languages those aren't interchangeable. I kind of miss having 0 and false be interchangeable, but with boolean being an actual type you can have methods and objects associated with it so that's just a tradeoff.
Null is null though, the absence of anything essentially. I usually also prefer to use 0. In pretty much all modern languages, null logically refers to pointers or references not having a value, or a variable that is not initialized. To make things complicated, in C, for example, null, 0, and false are all represented the exact same way. I don't know how it works in PHP.
Then, to complicate things more, databases have a concept of null, which means missing or not applicable, and most languages don't have a direct way to map a DBNull to their null. Until recently, for example, there was no distinction between an int being null and being zero, but that was changed with nullable ints. Sorry to make this sound complicated. It's just that this has been a harry sticking point in languages for years, and up until recently, it hasn't had any clear resolution anywhere.
People used to just kludge things together or make blank or 0 represent nulls in the database, which doesn't always work too well. False and 0 are conceptually similar, i. In other words, 0 can be defined as the number which, when added to some natural number, yields that same number:. Similarly, False is a value such that a disjunction of it and any other value is that same value:. Null is conceptually something totally different. Depending on the language, there are different semantics for it, but none of them describe an "initial value" as False and 0 are.
There is no algebra for Null. It pertains to variables, usually to denote that the variable has no specific value in the current context. In most languages, there are no operations defined on Null, and it's an error to use Null as an operand. In some languages, there is a special value called "bottom" rather than "null", which is a placeholder for the value of a computation that does not terminate.
I've written more extensively about the implications of NULL elsewhere. The issues with falsyness comes from the PHP history.
The problem targets the not well defined scalar type. PHP7 strictness is a step forward, but maybe not enough. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Null vs. False vs. Asked 13 years, 3 months ago. Active 1 year, 5 months ago. Viewed k times. Improve this question. Ben 9, 5 5 gold badges 39 39 silver badges 42 42 bronze badges.
It's almost impossible to actually really figure out when what is used. I prefer using null when retrieving a value from a method, because I can use isset to determine whether a value is returned instead of using empty which will not take in account: false , 0 , '0' or an empty string, which can be viable values in many situations. To me it's the cleanest solution in a messy construct.
As per gcb comment stackoverflow. By default, use triple unless you explitely want 0 to be considered as Null or false or the other way — Harps. Add a comment. Active Oldest Votes. It's language specific, but in PHP : Null means " nothing ". So why are they useful? Improve this answer. Robert 1, 1 1 gold badge 16 16 silver badges 36 36 bronze badges. Note about Null: PHP uses it as "no value" but this is not a good habit to get into.
In general, Null means "unknown value" which is different than "no value" or "uninitialized variable". Nothing plus 1 is 1, while an unknown value plus one is an unknown value. Just remember that any operator applied to null will should result in null, because any operation on an "unknown value" results in an unknown value. Eli: where do you get the idea that Null means "unknown value" in general. I can't think of any computer languages where this is true, nor does it mean that in English, at least not according to any definition I can find or have heard.
Maybe you know something I don't know? Question is about the programming language. PabloPazos why are you pinging me after 6 years have gone by? Plus, if you read my comment again, you will see probable relevance. Look at the keyword "unless" which would be a possible truth. PabloPazos its a bit ridiculous to even make a comment like yours, what he said is completely relevant and helpful.
If someone else came along and looked at this whilst having a DB error it would help fast track a solution, those who its not relevant too will simply move on and look at another answer. FunkFortyNiner Thanks for your comment, that was exactly what I needed to hear. I don't quite understand how this is possible, but I arrived at this page with this problem. Show 2 more comments. Active Oldest Votes.
Null is case insensitive. From the documentation : There is only one value of type null, and that is the case-insensitive keyword NULL. Improve this answer. Unless an exact match in DB is queried.
I'm having issue comparing null value getting from Database query. Can you help? Their NULL have different behaviors. For those who are now wondering whether it is better to write the keyword in upper or lower case.
0コメント