Variable Highlighting scope doesnt handle foreach properly

i have similar issue and believe it’s related. It highlights one vars and don’t highlight another.
Please see quick screen capture

My settings is following:

So i believe Komodo just don’t recognize foreach($array as $key => $val) construction correctly because if i uncheck “in scope” checkbox it works.

Moved your post into its own thread (came from Variable Highlighting suddenly stops working), please post a new thread for your issues rather than responding to old resolved ones.

I seem to be unable to reproduce your issue, I wrote a small test case to try and trigger the bug but it appears to work fine for me:


function foo()

    $object = ["one" => 1, "two" => 2, "three" => 3];

    foreach ($object as $key => $value)
        echo $value;


All variables are properly highlighted when selected. Could you provide a code snippet that reproduces your problem?


This part


        foreach (Yii::app()->log->routes as $route)
            $route->enabled = false;
        $numResults = Claim::model()->count($Criteria);

        // Set up pagination
        $Pages = new CPagination($numResults);

here it will not highlight $exportCsv, $Criteria and $route
In your example all highlighted correctly.

Hmm I’m not able to reproduce it with that snippet.

If you create a new file and paste in that snippet, then save is (ensure its a PHP file in Komodo); does it highlight things properly?

May be it something in my settings? Because i done same thing. I was copied that part from my working file, create new file, save it as .php and paste that part in it.

Now i check it one more time but copy snippet from this page. And it still reproduces but now $route was highlighted and $Criteria and $exportCsv still not, but i think it’s because that variables isn’t initialized before.

Here is screen capture for it

But here is another example

    $cart = array();
    foreach ($cart['Track'] as $tindex => $track){
        $track['licenses_type_id'] = $cart_licenses[$track['Track']['id']];
        $tindex += 3;

Being copied and pasted it doesn’t work: $track and $tindex doesn’t highlights. But if i erase [‘Track’] near $cart it works. Even if i return [‘Track’] back it stil working! Very strange behavior.

See it here:

PS newermind the code itself, i’m trying to minimize it as possibe so it’s just random lines from actual code.

Could you post your error log once you’ve reproduced the issue? Help > Troubleshooting > View Log File.

There are nothing related to this issue in log. Last message is two minutes before i reproduce this.

[2014-09-18 14:07:02,792] [WARNING] koInitService: Unable to determine the current locale settings, defaulting to mac-roman
[2014-09-18 14:07:21,883] [DEBUG] places_js: waiting for document complete
[2014-09-18 14:07:22,026] [WARNING] root: ko.findresults was already loaded, re-creating it.

[2014-09-18 14:07:33,640] [WARNING] views: Inconsistent view count in view_closed event

Now i found one more construction:

$code = array();
if (true)
    $discount = function($price) use (&$code)
        return $price*($code);

i run into such issue very often. I have send you entire file privately. May be it’s some case of complex issue. Please do not share it.

I’ll respond here in case anyone else is reading (or will be reading) this.

I’m still unable to reproduce the issue with either the provided snippets or the file you shared with me in private. I did notice though that you named 2 variables in the privately shared file that are only letter in length. Note that your “Variable Highlighting” settings are set by default to a minimum length of “4”, and in your screenshot to “2”, so that would explain why those dont work.

@toddw anything you can think of that we could try to reproduce his issue? Could it be related to the version of PHP installed?

@nathanr i know about setting of 2 letters length and mention that in your private message. Regardless that setting i have other one letter variable that IS highlighted.

Here is screen capture where you can see that setting isn’t respected and at least the different one letter vars is highlighted

In case it’s related to versions i’m using:
Komodo Edit, version 8.5.4, build 14424, platform macosx. Built on Wed Aug 13 23:56:46 2014.
Mac OS X 10.6.8

Setting for PHP at Prefs —> Languages —> PHP under “use this interpreter” i have “Find on path” other fields is empty, “Comment style” —> “//”

$php -v
PHP 5.3.26 (cli) (built: Jul 7 2013 18:30:38)
Copyright © 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright © 1998-2013 Zend Technologies

May be i can share other related settings? Or may be i can reset settings to default?

Also there are many record in the log now, may be something is related, please check it out:

That is indeed strange.

@yark - what happens when you perform a goto definition on the variable that’s not highlighting… I’m wondering if it can even find the definition.

BTW, the version of PHP doesn’t have any affect on the highlighting.

Here is record from log after i try to go to definition (Cmd+Click):

[2014-09-19 02:09:45,110] [ERROR] koCodeIntel: error evaluating definition:
trigger: <Trigger 'php-defn-defn' at 70201 (explicit)>
INFO: eval 'track' at AppController.php#2166  <Trigger 'php-defn-defn' at 70201 (explicit)>
INFO: start scope is (<blob 'AppController.php'>, ['AppController', 'calculate_cart'])
INFO: _hit_from_citdl:: expr: u'track', scoperef: (<blob 'AppController.php'>, ['AppController', 'calculate_cart'])
INFO: _hit_from_citdl:: expr tokens: [u'track']
INFO: _hits_from_first_part:: find 'track ...' starting at (<blob 'AppController.php'>, ['AppController', 'calculate_cart']):
INFO: _hits_from_first_part:: scoperef now (<blob 'AppController.php'>, ['AppController', 'calculate_cart']):
INFO: _return_with_hit:: hit was a not_yet_defined, ignoring it: (<variable 'track'>, (<blob 'AppController.php'>, ['AppController', 'calculate_cart']))
INFO: _hits_from_first_part:: checking namespace aliases
INFO: _hits_from_first_part:: pt3: is 'track' accessible on (<blob 'AppController.php'>, ['AppController', 'calculate_cart'])? no
INFO: _hits_from_first_part:: scoperef now (<blob 'AppController.php'>, []):
INFO: _hits_from_first_part:: checking namespace aliases
INFO: _hits_from_first_part:: module: 'Net/GeoIP.php', symbol: None, alias: None
INFO: _hits_from_first_part:: module: 'Vendor', symbol: None, alias: None
INFO: _hits_from_first_part:: pt3: is 'track' accessible on (<blob 'AppController.php'>, [])? no
DEBUG: _hit_from_elem_imports:: Checking imports, tokens[0]: u'track' ... imp_elem: <blob 'AppController.php'>
DEBUG: _hit_from_elem_imports:: import 'track ...' from <import Net/GeoIP.php>?
INFO: is blob 'Net/GeoIP.php' from <PHP curdirlib>? no
INFO: is blob 'Net/GeoIP.php' from <PHP cataloglib: HTML5, jQuery>? no
INFO: is blob 'Net/GeoIP.php' from <php-5.3 stdlib>? no
DEBUG: _hit_from_elem_imports:: Failed import: Net/GeoIP.php
DEBUG: _hit_from_elem_imports:: import 'track ...' from <import Vendor>?
INFO: is blob 'Vendor' from <PHP curdirlib>? no
INFO: is blob 'Vendor' from <PHP cataloglib: HTML5, jQuery>? no
INFO: is blob 'Vendor' from <php-5.3 stdlib>? no
DEBUG: _hit_from_elem_imports:: Failed import: Vendor
INFO: _hit_from_elem_imports:: trying import everything: tokens: [u'track']
INFO: _hit_from_elem_imports:: trying with lpath: (u'track',)
INFO: _hit_from_elem_imports:: ie: lookup (u'track',) in <PHP curdirlib> => []
INFO: _hit_from_elem_imports:: ie: lookup (u'track',) in <PHP cataloglib: HTML5, jQuery> => []
INFO: _hit_from_elem_imports:: ie: lookup (u'track',) in <php-5.3 stdlib> => []
INFO: _hit_from_elem_imports:: ie: no matches found
ERROR: evaluating 'track' at AppController.php#2166: could not resolve first part of 'track'

Thanks for the log - it seems the foreach wasn’t being correctly parsed by Komodo… I believe I’ve got a fix for this in change:

1 Like