API page: http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_g...

Enter a descriptive title (above) relating to drupal_get_path, then describe the problem you have found:
There is no mention of what happens when the file is not found. A quick test shows the file function returns a binary zero and that makes dirname return an empty string.
drupal_get_path('module', 'sdkjghfsdjklghfsdkjghfds'); returns an empty string.
There may be other possibilities in the code.

Files: 
CommentFileSizeAuthor
#11 common.inc-documentation-1908194-11.patch522 bytesrichard.c.allen2386
PASSED: [[SimpleTest]]: [MySQL] 49,400 pass(es).
[ View ]
#4 common.inc-documentation-1908194-4.patch510 bytesrichard.c.allen2386
PASSED: [[SimpleTest]]: [MySQL] 49,190 pass(es).
[ View ]
#2 common.inc-documentation-1908194-2.patch521 bytesrichard.c.allen2386
PASSED: [[SimpleTest]]: [MySQL] 49,395 pass(es).
[ View ]

Comments

Title:Returns FALSE if the file is not found.Document that drupal_get_path() returns an empty string if the file is not found
Version:7.x-dev» 8.x-dev
Issue tags:+Novice, +needs backport to D7

Thanks -- we should document this in 8.x first and then backport to 7.x.

Status:Active» Needs review
StatusFileSize
new521 bytes
PASSED: [[SimpleTest]]: [MySQL] 49,395 pass(es).
[ View ]

Here you go, this should be good?

Status:Needs review» Needs work

Thanks! Can you clean up the grammar and combine the two possibilities? Something like:
@return
Blah blah blah, or foo if (whatever, but include a verb).

StatusFileSize
new510 bytes
PASSED: [[SimpleTest]]: [MySQL] 49,190 pass(es).
[ View ]

re-rolled, wasn't quite clear on the second part nor was anyone else in the office. maybe we're all terrible at grammar!

Status:Needs work» Needs review

How about "... if the file is not found" for the second part?

It is less clear to call a module a "file" than an "item" so perhaps something like "....or an empty string if the item is not found." Perhaps something like the following:

/**
* Returns the path to a system item (module, theme, etc.).
*
* @param $type
*   The type of the item (i.e. theme, theme_engine, module, profile).
* @param $name
*   The name of the item for which the path is requested.
*
* @return
*   The path to the requested item or an empty string if the item is not found.
*/
function drupal_get_path($type, $name) {
  return dirname(drupal_get_filename($type, $name));
}

#7 seems fine to me. Just make sure the line wraps if it goes over 80 characters. Thanks!

Looks like drupal_get_filename() returns NULL not an empty string when the file does not exist. There should be a test that asserts this.

StatusFileSize
new522 bytes
PASSED: [[SimpleTest]]: [MySQL] 49,400 pass(es).
[ View ]

I re-rolled using the comment from #7. The test function in #10 seems to indicate that it is an empty string.

Assigned:Unassigned» jhodgdon
Status:Needs review» Reviewed & tested by the community

Thanks! I'll get this committed when the test result turns green.

Does the backport for V7 go in this issue too?

It will, but wait until the 8.x version is committed. Often the same patch can be applied and no one has to do any more work backporting it. :)

Status:Reviewed & tested by the community» Fixed

Thanks again -- Committed to both 8.x and 7.x (no port required).

Assigned:jhodgdon» Unassigned

Automatically closed -- issue fixed for 2 weeks with no activity.