davidearl / webauthn

An implementation of webauthn in PHP on the server side (e.g Yubico 2 and Google Titan keys)
https://webauthn.davidearl.uk
MIT License
129 stars 24 forks source link

Setting unknown property: appid for local host #56

Open rohitgour45 opened 1 year ago

rohitgour45 commented 1 year ago

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:// / } }

PHPGangsta commented 1 year ago

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;
...
davidearl commented 1 year ago

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.

PHPGangsta commented 1 year ago

@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

davidearl commented 1 year ago

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.