我为什么需要"&"?

isr*_*php 4 php oop

请参阅Web上有关PHP Factory Pattern的示例.

在线$kind =& Vehicle::category($wheel);,我为什么要使用&

代码:

<?php
    class Vehicle {

        function category($wheel = 0) {
            if ($wheel == 2) {
                return "Motor";
            } elseif($wheel == 4) {
                return "Car";
            }
        }
    }

    class Spec {

        var $wheel = '';

        function Spec($wheel) {
            $this->wheel = $wheel;
        }

        function name() {
            $wheel = $this->wheel;
                return Vehicle::category($wheel);
        }

        function brand() {
            $wheel = $this->wheel;
                $kind =& Vehicle::category($wheel);
            if ($kind == "Motor") {
                return array('Harley','Honda');
            } elseif($kind = "Car") {
                return array('Nisan','Opel');
            }
        }
    }

    $kind = new Spec(2);
    echo "Kind: ".$kind->name();
    echo "<br>";
    echo "Brand: " . implode(",", $kind->brand());
?>
Run Code Online (Sandbox Code Playgroud)