Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'use'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 2 results

  1. In the "Namespaces" section in Ch.6, Larry describes how the use keyword can allow us to reference a namespace once in our script so that we don't need to name the specific namespace over and over again when we make objects: Unfortunately, I am getting a class not found error when I try to use this. See program below, a shorter version of the type hinting example used earlier in the book. Company.php <?php namespace MyNamespace\Company; class Department{ private $_name; private $_employees; function __construct($name){ $this->_name = $name; $this->_employees = array(); }//__construct function addEmployee(Employee $e){ $this->_employees[] = $e; echo "<p>{$e->getName()} has been added to the {$this->_name} department.</p>"; }//addEmployee }//Department class Employee{ private $_name; function __construct($name){ $this->_name = $name; } function getName(){ return $this->_name; }//getName }//Employee ?> Using use in a separate file in the same directory as Company.php: <?php require('Company.php'); use MyNamespace\Company; $hr = new Department("Human Resources"); $e1 = new Employee("mary"); $hr->addEmployee($e1); ?> The code above generates a fatal error: "Fatal error: Class 'Department' not found" Am I missing something or am I not using use properly? Any assistance is greatly appreciated.
  2. Page 211: [Tip] PHP allows you to more quickly reference namespaces...use keyword: Book says (incorrect): use MyNameSpace\Company; Should be (corrected): use MyNameSpace\Company\Department; use MyNameSpace\Company\Employee; All class names used must be included at the end of the namespace.
×
×
  • Create New...