Jump to content

[Solved] - Syntax help, PHP error when Debug is on (code working)

Recommended Posts

I have this line of code on one of my templates:

$field = $fields->get('artcategories');
$all_options = $field->type->getOptions($field);
$selected_option = $all_options->get('2');
echo $selected_option->title

The line highlighted in red throws the error
Notice: Use of undefined constant  - assumed '' in /public_html/site/assets/cache/FileCompiler/site/templates/samplepage.php on line 45

I looked into the issue and it's usually a lack of quotes, presumably it's the getOptions($field) requires quotes but with quotes the script won't work.

Edit: I think one of the quotes what copied from elsewhere and was the wrong ansii character @ 
$all_options->get('2');, i.e the wrong apostrophe, so it was throwing the syntax error.

Share this post

Link to post
Share on other sites

@PCuser not sure if it's related but I've often had similar errors when copy/pasting sample code from the PW docs/forums. Maybe it picks up some 'invisible' extra code or spaces? Now I copy/paste to a plain text editor first before adding to my template - same as I'd do for MS Word - and it seems to fix the problem

  • Like 4

Share this post

Link to post
Share on other sites
10 hours ago, Soma said:

It's not an error but a notice.

Depends on how you look at it 😛 Strictly speaking it was a Notice, for sure. However, it turned out that it was also a "copy/paste error"... 😄

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...