Method chaining error

已回答

I posted a while back in https://youtrack.jetbrains.com/issue/WI-24761 some sample code where PHPStorm seems to loose track of the return type when doing method chaining.  This issue was recently closed as non-reproducible so I updated to the latest version and tried it again only to discover the problem seems to still exist.

Maybe a separate issue needs to be opened for my code but it seemed fairly similar to that report so which is why I posted it there.  I find the Youtrack system difficult to search for existing reports so I'm not sure if this exists already as another report or if a new one needs made.

0

The originally reported case isn't reproducible anymore:

<?php

namespace one {
class Foo {
const BAR = 'bar';
}

class FooService {

public function test() {
echo 'called';
}
}
}

namespace {
use one\FooService;

/**
* @return FooService
*/
function foo() {
return new FooService();
}
}

namespace two {
use one\Foo;

foo()->test(Foo::BAR);
}

Do you have another example?

0
Avatar
Permanently deleted user

Maybe it's an entirely separate error but it seemed related so I just attached it to that bug.  There is a full sample code file and image showing the problem in that bug report.

 

interface AddressInterface {
public function getFirstname();
public function getLastname();
public function getAddress();
public function getCity();
public function getState();
public function getPostalCode();
public function getPhoneNumber();
}


class Address implements AddressInterface {
private $firstname;
private $lastname;
private $address;
private $city;
private $state;
private $postalCode;
private $phoneNumber;

public function __construct($firstname, $lastname, $address, $city, $state, $postalCode, $phone = ''){
$this
->setFirstname($firstname)
->setLastname($lastname)
->setAddress($address)
->setCity($city)
->setState($state)
->setPostalCode($postalCode)
->setPhoneNumber($phone)
;
}

public function setFirstname($firstname){
$this->firstname = $firstname;

return $this;
}

// ...
}

 

After a couple calls PHPStorm no longer recognizes the return type and complains about the method not existing.

https://youtrack.jetbrains.com/_persistent/Error.png?file=74-270496&c=true&rw=791&rh=195&u=1447917640855&c=true&rw=791&rh=195

0

Yup, it would be better to add your example to above-mentioned report.

0

请先登录再写评论。