PCuser

[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

It's not an error but a notice. 🙂

  • Like 2

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.