Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

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

@Krinkle

Description

@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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions