You can access properties via `$` and its name

Open
#925 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
php
Domain
compilers

Research direction

Use the provided PHP example as the reproduction and compare KPHP's array output with native PHP's output for $this->$name. Trace the compiler handling for variable property names; done means KPHP preserves the value of the variable as the property key and matches PHP's output.

Written by the indexing model from the issue text.

Description

bug
<?php

main();

function main() {
  $cls = new TestClass();
  $cls->getName("test");

  var_dump(instance_to_array($cls));
}

class TestClass {
  private string $name;

  function getName(string $name): void {
    $this->$name = $name;
//         ^ <- error is here
  }
}

Output to KPHP:

array(1) {
  ["name"]=>
  string(4) "test"
}

Output to PHP:

array(1) {
  'test' =>
  string(4) "test"
}
Dominant language
C++
Stars
1.5k
Forks
116
Avg merge
5d 17h
Merged PRs (30d)
11

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from VKCOM/kphp

All issues in VKCOM/kphp

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.