sanchescom / php-wifi

Cross-platform PHP library for scan, connect and disconnect Wi-Fi networks.
GNU General Public License v3.0
49 stars 14 forks source link

Fatal error #12

Closed fcordillot closed 3 months ago

fcordillot commented 4 years ago

Hi πŸ‘‹

I'm getting a Fatal error when I'm using your README code.

CODE:

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

include __DIR__ . '/vendor/autoload.php';

use Sanchescom\WiFi\WiFi;

class Example
{
    public $device;

    /**
     * @throws Exception
     */
    public function getAllNetworks()
    {
        $networks = WiFi::scan()->getAll();

        foreach ($networks as $network) {
            echo $network . "\n";
        }
    }

    /**
     * @param $ssid
     * @param $password
     */
    public function connect($ssid, $password)
    {
        try {
            WiFi::scan()->getBySsid($ssid)->connect($password, $this->device);
        } catch (Exception $exception) {
            echo $exception->getMessage();
        }
    }

    /**
     * @throws Exception
     */
    public function disconnect()
    {
        $networks = WiFi::scan()->getConnected();

        foreach ($networks as $network) {
            $network->disconnect($this->device);
        }
    }
}

$example = new Example();
try {
    $example->device = 'en1';
    $example->getAllNetworks();
    $example->connect('Redmi', '12345');
    $example->disconnect();
} catch (Exception $e) {
    //
}

ERROR:

Fatal error: Declaration of Sanchescom\WiFi\System\Darwin\Networks::extractingNetworks($output): array must be compatible with Sanchescom\WiFi\System\AbstractNetworks::extractingNetworks(string $output): array in /Users/floriancordillot/Projets/wifi-connect/vendor/sanchescom/php-wifi/src/System/Darwin/Networks.php on line 14
sanchescom commented 4 years ago

Do you still get this error or probably you found a reason. This is looks like you don't have any wifi networks. If you still see the error show me what return this command please:

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s && echo "--separator--" && /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport --getinfo