Bug 443037 - Restricted word 'parent' can be used as class name (no error)
Summary: Restricted word 'parent' can be used as class name (no error)
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: PDT (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: PHP Core CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-01 13:10 EDT by Michal Niewrzal CLA
Modified: 2020-05-14 11:24 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michal Niewrzal CLA 2014-09-01 13:10:33 EDT
Word 'parent' is highlighted as keyword, but no errors are displayed.

To reproduce:
<?php
class parent {
}

http://3v4l.org/MBgjE
Comment 1 Eclipse Genie CLA 2019-04-29 10:09:00 EDT
New Gerrit change created: https://git.eclipse.org/r/141337
Comment 3 Thierry BLIND CLA 2019-04-30 08:59:58 EDT
Fixed.

Note that my patch does only a minimal and non-intrusive fix by checking that class, interface, trait and namespace declarations don't use "parent", "self" or any of the restricted words defined at https://www.php.net/manual/en/reserved.other-reserved-words.php

We could also check class instantiations, class and interface heritage, restrict TI and CA, but php behavior is not trivial (and can also depend on the namespace context).
For example, this is *valid* in PHP 7.2:

class A extends \self {
    function foo() {
        $a = new self();
    }
}
class B extends \parent {
}

but following examples would result in a different type of error, i.e. a "Class 'float' not found" error:

class A extends \float {
}

class B extends float {
}

So keep the fix as simple as possible and avoid introducing regressions ;)

Thierry.