Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

PHP Strict: Use of undefined constant in ./docs/pages/dynamic-samples/category.php #5314

Closed
Krinkle opened this Issue · 0 comments

2 participants

@Krinkle

The error logs are full of this:

PHP Notice:  Use of undefined constant vehicles - assumed 'vehicles' in build/jquery-mobile/2eb52813d622b5e9780a3dd6c6872563cd5ef1f8/docs/pages/dynamic-samples/category.php on line 53
PHP Notice:  Use of undefined constant name - assumed 'name' in build/jquery-mobile/2eb52813d622b5e9780a3dd6c6872563cd5ef1f8/docs/pages/dynamic-samples/category.php on line 54PHP Notice:  Use of undefined constant description - assumed 'description' in build/jquery-mobile/2eb52813d622b5e9780a3
dd6c6872563cd5ef1f8/docs/pages/dynamic-samples/category.php on line 55
PHP Notice:  Use of undefined constant items - assumed 'items' in build/jquery-mobile/2eb52813d622b5e9780a3dd6c6872563cd5ef1f8/docs/pages/dynamic-samples/category.php on line 56
PHP Notice:  Use of undefined constant name - assumed 'name' in build/jquery-mobile/2eb52813d622b5e9780a3dd6c6872563cd5ef1f8/docs/pages/dynamic-samples/category.php on line 58
PHP Notice:  Use of undefined constant name - assumed 'name' in build/jquery-mobile/2eb52813d622b5e9780a3dd6c6872563cd5ef1f8/docs/pages/dynamic-samples/category.php on line 61
PHP Notice:  Use of undefined constant name - assumed 'name' in build/jquery-mobile/2eb52813d622b5e9780a3dd6c6872563cd5ef1f8/docs/pages/dynamic-samples/category.php on line 64

Caused by (sample below) introduced in cac2032 (cc @jblas):

$category_data = array(
    animals => array(
        name => "Animals",
        description => "All your favorites from aardvarks to zebras.",
        items => array(
 [..]

This isn't javascript, no unquoted keys here! Unforunately, not unlike javascript, PHP is famous for not letting failures show very visibly.

In this case it will actually try to access a global constant named animals (conventions usually recommend constants be written in CAPS). And if it can't find that constant, it will use its name as a string value and continue on (Yes this means in PHP, array keys can be created from expressions).

Just quote them, and don't forget to develop locally with error_reporting -1 (all errors), and keep an eye on /var/log/apache2/error_log (or your local equivalent).

@toddparker toddparker closed this issue from a commit
@Krinkle Krinkle Clean up dynamic-samples/category.php. Fixes #5314.
Fixes there errors:

PHP Notice:  Use of undefined constant vehicles - assumed 'vehicles' in ./docs/pages/dynamic-samples/category.php on line 53

PHP Notice:  Use of undefined constant name - assumed 'name' in ./docs/pages/dynamic-samples/category.php on line 54

PHP Notice:  Use of undefined constant description - assumed 'description' in ./docs/pages/dynamic-samples/category.php on line 55

PHP Notice:  Use of undefined constant items - assumed 'items' in ./docs/pages/dynamic-samples/category.php on line 56

PHP Notice:  Use of undefined constant name - assumed 'name' in ./docs/pages/dynamic-samples/category.php on line 58

PHP Notice:  Use of undefined constant name - assumed 'name' in ./docs/pages/dynamic-samples/category.php on line 61

PHP Notice:  Use of undefined constant name - assumed 'name' in ./docs/pages/dynamic-samples/category.php on line 64

PHP Notice:  Undefined index: id in ./docs/pages/dynamic-samples/category.php on line 74

PHP Notice:  Undefined index:  in ./docs/pages/dynamic-samples/category.php on line 82

PHP Notice:  Undefined index: HTTP_X_REQUESTED_WITH in ./docs/pages/dynamic-samples/category.php on line 88

Also added charset in Content-Type header and used json_encode
instead of homebrew unescaped json encoder.

Follows-up cac2032
6131785
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.