1

I got 2 PHP files:

courier.php

    <?php
namespace Shipping;

class Courier
{
    public $name;
    public $home_country;

    public function __construct($name) {
        $this->name = $name;
        return true;
    }

    public function ship($parcel) {
        // sends the parcel to  its destination
        return true;
    }

    public static function getCouriersByCountry($country) {
        // get a list of couriers with their home_country = $country

        // create a Courier object for each result

        // return an array of the results
        return $courier_list;

    }

}
?>

filephp.php

<?php
//namespace Fred;

require 'courier.php';
//function __autoload($classname) {
//    include //strtolower($classname).'.php';
//}

$mono = new Shipping\Courier('Monospace Delivery');

//var_dump($mono);

// accessing a property
echo "Courier Name: " . $mono->name;

// calling a method
$mono->ship($parcel);

$spanish_couriers = Courier::getCouriersByCountry('Spain');

echo $spanish_couriers;
?>

But when I execute filephp.php I get this error:

Fatal error: Class 'Courier' not found in D:\masterphp\test.php on line 19

line 19 is this:

$spanish_couriers = Courier::getCouriersByCountry('Spain');

What is wrong with my scope resolution?

2
  • Directory is same??? For courier.php Commented Feb 25, 2016 at 20:13
  • all files in same directory. Commented Feb 25, 2016 at 20:13

1 Answer 1

1

You are missing the Shipping namespace, it should be \Shipping\Courier::...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.