webauthn icon indicating copy to clipboard operation
webauthn copied to clipboard

Setting unknown property: appid for local host

Open rohitgour45 opened this issue 2 years ago • 5 comments

For local machine when I am trying to run this code its showing me appid issue for class contractor method, here I can see need to pass host name as argument and I am passing localhost but its not working and showing error.

public function __construct($appid) { if (! is_string($appid)) { $this->oops('appid must be a string'); } $this->appid = $appid; if (strpos($this->appid, 'https://') === 0) { $this->appid = substr($this->appid, 8); /* drop the https:// */ } }

rohitgour45 avatar Oct 13 '22 09:10 rohitgour45

I guess you are talking about a "Notice" which is new in PHP 8.0, that occurs if you access an undefined property in a class. You should be able to fix it if you create the class property:

class WebAuthn
{
    /**
     * @var string
     */
    public $appid;
...

PHPGangsta avatar Nov 08 '22 16:11 PHPGangsta

There is no requirement in any version of PHP to declare properties. They tightened up implicit object creation, and reading unset properties, but there isn't any error, notice or otherwise, in assigning to a new property. I wrote a quick test just to make sure. Adding properties dynamically is very widely used.

I don't really think it is appropriate to use localhost for this, and you really must use https, it's pointless otherwise.

If you could post the actual error with the line numbers, and the exact string you pass in, that would be helpful. It has to match the host in the origin returned in the response later on, but that doesn't sound like the error you're getting.

davidearl avatar Nov 08 '22 23:11 davidearl

@davidearl If you don't declare properties, in PHP 8.x you get Notices, Warnings when reading. In >=8.2 you'll get Notices when writing to an undeclared property.

In PHP 9 you'll get Errors. Please read:

https://wiki.php.net/rfc/deprecate_dynamic_properties

PHPGangsta avatar Nov 09 '22 00:11 PHPGangsta

Quite. 8.2 which isn't released yet. Unless @rohitgour45 is using a pre-release 8.2, this is not the problem above: it is only writing. Not saying it wouldn't be good to declare it, but it's not the immediate issue.

davidearl avatar Nov 09 '22 15:11 davidearl

I would say it is now an issue as 8.2 is very much released

andymilsted avatar Jul 19 '24 09:07 andymilsted