# Double-Colon Always Follows the 'parent' Keyword?

- Thread: https://externals.io/message/66581
- Original archive: https://news-web.php.net/php.internals/66581
- Started by Eric James Michael Ritz on 2013-03-11T11:19:48+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #66581 — Eric James Michael Ritz — 2013-03-11T11:19:48+00:00

URL: https://externals.io/message/66581#66581

Hello everyone,

I have a question about the internals of PHP, but this is not about
advancing the development of the language, so I apologize if this is
on the wrong list.  I am choosing to post to this list because I
believe the people here are most qualified to answer my question.

This is what I want to know: Is there any valid situation in PHP where
the ‘parent’ keyword is not followed by the scope-resolution operator?
I am asking to help me decide on the best way to fix a bug for
php-mode[1] for GNU Emacs.  Consider these three lines:

     echo $parent;
     echo parent::$foo;
     echo $this->parent;

Emacs correctly highlights the first ‘parent’ as a variable name.  It
also highlights ‘parent’ in the second line as a keyword, as it
should.  But in the third line it treats ‘parent’ as a keyword instead
of a variable and applies the wrong syntax formatting.

My idea to fix this problem is to only treat ‘parent’ as a keyword if
the scope-resolution operator immediately follows it.  But before
doing that I want to know whether or not that is true.  So is there
are valid situation where the keyword ‘parent’ does not have ‘::’
after it?

Thank you in advanced for any advice and help.



[1]: https://github.com/ejmr/php-mode

--
ejmr
南無妙法蓮華經

---

## #66584 — keisial@gmail.com — 2013-03-11T12:19:11+00:00

URL: https://externals.io/message/66581#66584 · In reply to: #66581

> Hello everyone,
>
> I have a question about the internals of PHP, but this is not about
> advancing the development of the language, so I apologize if this is
> on the wrong list.  I am choosing to post to this list because I
> believe the people here are most qualified to answer my question.
>
> This is what I want to know: Is there any valid situation in PHP where
> the ‘parent’ keyword is not followed by the scope-resolution operator?
> I am asking to help me decide on the best way to fix a bug for
> php-mode[1] for GNU Emacs.  Consider these three lines:
>
>     echo $parent;
>     echo parent::$foo;
>     echo $this->parent;
>
> Emacs correctly highlights the first ‘parent’ as a variable name.  It
> also highlights ‘parent’ in the second line as a keyword, as it
> should.  But in the third line it treats ‘parent’ as a keyword instead
> of a variable and applies the wrong syntax formatting.
>
> My idea to fix this problem is to only treat ‘parent’ as a keyword if
> the scope-resolution operator immediately follows it.  But before
> doing that I want to know whether or not that is true.  So is there
> are valid situation where the keyword ‘parent’ does not have ‘::’
> after it?
>
> Thank you in advanced for any advice and help.

Hello Eric
Wouldn't it be simpler to check that parent if preceded by
whitespace/brackets?
Checking if it's followed by the paamayim nekudotayim, seems also ok.

---

## #66586 — Eric James Michael Ritz — 2013-03-11T12:55:52+00:00

URL: https://externals.io/message/66581#66586 · In reply to: #66584

> 
> > […]
 >
 > Hello Eric
 >
 > Wouldn't it be simpler to check that parent if preceded by
 > whitespace/brackets?  Checking if it's followed by the paamayim
 > nekudotayim, seems also ok.

Thanks for the idea.  Checking for brackets would work but not
whitespace since PHP allows programmers to write code such as

     echo $this->  parent;        // Same as $this->parent

So perhaps checking for paamayim nekudotayim would be best.

--
ejmr
南無妙法蓮華經

---

## #66588 — Kalle Sommer Nielsen — 2013-03-11T14:39:32+00:00

URL: https://externals.io/message/66581#66588 · In reply to: #66586

Hi

Den 11/03/2013 kl. 13.55 skrev Eric James Michael Ritz <lobbyjones@gmail.com>:
> 
> Thanks for the idea.  Checking for brackets would work but not
> whitespace since PHP allows programmers to write code such as
> 
>    echo $this->  parent;        // Same as $this->

Technically "parent" and "self" is not keywords, they are implemented as T_STRING. These are only used as keywords when the next non whitespace token is a double colon, like:

self::$property->...

So I would continue reading until the next token and decide from there if its used in a "keyword-context" or not to decide its syntax highlight color.

-K

---

## #66589 — Nikita Popov — 2013-03-11T14:43:15+00:00

URL: https://externals.io/message/66581#66589 · In reply to: #66581

On Mon, Mar 11, 2013 at 12:19 PM, Eric James Michael Ritz <
lobbyjones@gmail.com> wrote:

> Hello everyone,
>
> I have a question about the internals of PHP, but this is not about
> advancing the development of the language, so I apologize if this is
> on the wrong list.  I am choosing to post to this list because I
> believe the people here are most qualified to answer my question.
>
> This is what I want to know: Is there any valid situation in PHP where
> the ‘parent’ keyword is not followed by the scope-resolution operator?
> I am asking to help me decide on the best way to fix a bug for
> php-mode[1] for GNU Emacs.  Consider these three lines:
>
>     echo $parent;
>     echo parent::$foo;
>     echo $this->parent;
>
> Emacs correctly highlights the first ‘parent’ as a variable name.  It
> also highlights ‘parent’ in the second line as a keyword, as it
> should.  But in the third line it treats ‘parent’ as a keyword instead
> of a variable and applies the wrong syntax formatting.
>
> My idea to fix this problem is to only treat ‘parent’ as a keyword if
> the scope-resolution operator immediately follows it.  But before
> doing that I want to know whether or not that is true.  So is there
> are valid situation where the keyword ‘parent’ does not have ‘::’
> after it?
>
> Thank you in advanced for any advice and help.
>

parent and self are not keywords, they are just special class names. Apart
from that they can be freely used, e.g. you could also have a constant
called "parent".

The special meaning exists in (nearly) any classname context. parent::$foo
is just one case. It's just as special if you do new parent() or something
like that ;) So I don't think it makes sense to highlight only when
followed by ::

Nikita
