I guess it depends on what $indirec is expected to contain. The first will work if there is no $indirec returned. The second will only work if an empty record actually returns "false". The 3rd will work if the variable is present but empty. So it depends on what the function find_person_record returns if no record is found.
But then I'm an amateur, so I'm probably wrong :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Actually I guess I am wrong.
* "" (an empty string)
* 0 (0 as an integer)
* "0" (0 as a string)
* NULL
* FALSE
* array() (an empty array)
* var $var; (a variable declared, but without a value in a class)
Are all considered empty. So it looks like "empty" is the most versatile.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well, that advances my PHP education quite a bit, but I was hoping to avoid (possibly misinterpreted) experimentation to figure out the simplest reliable way to detect a nonexistent pid (as opposed to one that is private or public).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Why don't you check the code yourself? It begins at line 1160 of "includes/functions/functions_db.php".
A pid that refers to a non-existent record returns an empty string. This is evaluated as "false". The empty() test also returns true.
Your first two tests are equivalent. The third test is the one I'd use because it's a lot clearer. The problem with the first two tests is that they leave you guessing as to whether the function returns a real true or false or something else that's evaluated as true or false.
To be absolutely precise, you should really code:
if ($indirec == "") ....
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Wes
If I may, why exactly do you wish to know of a non-existant PID?
You can sort the SQL via PID and view the results, or to fill in on empty PIDs you can simply reset your NEXT PID in the Next ID numbers table to 1 and let it fill in the blanks as you create new people.
-Stephen
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Wes
If you use SEARCH, logged in or not, current SVN code returns the search page and NO RESULTS display.
If you use a URI on a non-existent INDI-ID # (whether previously existing or deleted as to the SQL they are one in the same) when not logged in, it still returns a note:
This information is private and cannot be shown. For more information contact...
If logged in and use a URI for a non-existent INDI-ID #, you'll get the UNK/UNK PF&D page.
If you use a URI on a non-existent FAM-ID #, you receive a fatal error, whether logged in or not. This last result has already been submitted as a bug in the tracker.
Stephen
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
not logged in, P9000 in search, "no results" -- good.
not logged in, F9000 in search, "no results" -- good.
non-admin, P9000 in search, "no results" -- good
non-admin, F9000 in search, "no results" -- good
admin, P9000 in search, "no results" -- good
admin, F9000 in search, "no results" -- good
admin, family.php?famid=F9000 fatal error trying to fetch children, which wouldn't happen if it said "nonexistent" and quit at the beginning. Title tag is:
‎‎(unknown)‎‎ ‎‎(unknown)‎‎ + ‎‎(unknown)‎‎ ‎‎(unknown)‎‎ ....
(Why all those LRMs ?)
admin, individual.php?pid=P9000:
(unknown) (unknown) (P9000)
Gender: unknown
Views of this page: 35517
There are no Facts for this individual. (misleading)
non-admin, family.php?famid=F9000 fatal error trying to fetch children, which wouldn't happen if it said "nonexistent" and quit at the beginning. Title tag is:
‎‎(unknown)‎‎ ‎‎(unknown)‎‎ + ‎‎(unknown)‎‎ ‎‎(unknown)‎‎ ....
(Why all those LRMs ?)
non-admin, individual.php?pid=P9000:
(unknown) (unknown) (P9000)
Gender: unknown
Views of this page: 35517
There are no Facts for this individual. (misleading)
not logged in, family.php?famid=F9000 fatal error trying to fetch children, same title tag
not logged in, individual.php?pid=P9000 "private and cannot be shown. For more information contact"
(No, please don't contact me for that!)
I'm all confused now, but I think this is confirming what Stephen posted.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
// After doing
$indirec = find_person_record($this->pid);
// What's the difference among these three lines?
if ( ! $indirec ) {
if ($indirec==false) {
if (empty($indirec)) {
I'm looking for an simple but not inefficient way to determine that the pid does not exist.
thanks
I guess it depends on what $indirec is expected to contain. The first will work if there is no $indirec returned. The second will only work if an empty record actually returns "false". The 3rd will work if the variable is present but empty. So it depends on what the function find_person_record returns if no record is found.
But then I'm an amateur, so I'm probably wrong :)
Actually I guess I am wrong.
* "" (an empty string)
* 0 (0 as an integer)
* "0" (0 as a string)
* NULL
* FALSE
* array() (an empty array)
* var $var; (a variable declared, but without a value in a class)
Are all considered empty. So it looks like "empty" is the most versatile.
Well, that advances my PHP education quite a bit, but I was hoping to avoid (possibly misinterpreted) experimentation to figure out the simplest reliable way to detect a nonexistent pid (as opposed to one that is private or public).
Why don't you check the code yourself? It begins at line 1160 of "includes/functions/functions_db.php".
A pid that refers to a non-existent record returns an empty string. This is evaluated as "false". The empty() test also returns true.
Your first two tests are equivalent. The third test is the one I'd use because it's a lot clearer. The problem with the first two tests is that they leave you guessing as to whether the function returns a real true or false or something else that's evaluated as true or false.
To be absolutely precise, you should really code:
if ($indirec == "") ....
Wes
If I may, why exactly do you wish to know of a non-existant PID?
You can sort the SQL via PID and view the results, or to fill in on empty PIDs you can simply reset your NEXT PID in the Next ID numbers table to 1 and let it fill in the blanks as you create new people.
-Stephen
I was looking to test a local fix to the issue of a non-existent pid being displayed as if it exists but is private (or exists but has no data)
I will take a look at the code Gerry pointed me to. The comments in the calling code were not helpful.
Wes
If you use SEARCH, logged in or not, current SVN code returns the search page and NO RESULTS display.
If you use a URI on a non-existent INDI-ID # (whether previously existing or deleted as to the SQL they are one in the same) when not logged in, it still returns a note:
This information is private and cannot be shown. For more information contact...
If logged in and use a URI for a non-existent INDI-ID #, you'll get the UNK/UNK PF&D page.
If you use a URI on a non-existent FAM-ID #, you receive a fatal error, whether logged in or not. This last result has already been submitted as a bug in the tracker.
Stephen
SVN 5010:
not logged in, P9000 in search, "no results" -- good.
not logged in, F9000 in search, "no results" -- good.
non-admin, P9000 in search, "no results" -- good
non-admin, F9000 in search, "no results" -- good
admin, P9000 in search, "no results" -- good
admin, F9000 in search, "no results" -- good
admin, family.php?famid=F9000 fatal error trying to fetch children, which wouldn't happen if it said "nonexistent" and quit at the beginning. Title tag is:
‎‎(unknown)‎‎ ‎‎(unknown)‎‎ + ‎‎(unknown)‎‎ ‎‎(unknown)‎‎ ....
(Why all those LRMs ?)
admin, individual.php?pid=P9000:
(unknown) (unknown) (P9000)
Gender: unknown
Views of this page: 35517
There are no Facts for this individual. (misleading)
non-admin, family.php?famid=F9000 fatal error trying to fetch children, which wouldn't happen if it said "nonexistent" and quit at the beginning. Title tag is:
‎‎(unknown)‎‎ ‎‎(unknown)‎‎ + ‎‎(unknown)‎‎ ‎‎(unknown)‎‎ ....
(Why all those LRMs ?)
non-admin, individual.php?pid=P9000:
(unknown) (unknown) (P9000)
Gender: unknown
Views of this page: 35517
There are no Facts for this individual. (misleading)
not logged in, family.php?famid=F9000 fatal error trying to fetch children, same title tag
not logged in, individual.php?pid=P9000 "private and cannot be shown. For more information contact"
(No, please don't contact me for that!)
I'm all confused now, but I think this is confirming what Stephen posted.