Click here to Skip to main content
15,909,466 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
PHP
<?php
class Cars {
	static $wheel_count = 4;
	static $door_count = 2;

	static function car_detail(){
		return self::$wheel_count;
		return self::$door_count;
	}
}
class Trucks extends Cars {

	static function display(){

		echo parent::car_detail();
	}
}

Trucks::display();

 ?>


What I have tried:

Hello, i have a question please, i'm a newbie on PHP and when i run this code i have as result 4.Why i don't have 4 and 2, i ran the function display to get wheel_count and door_count, so why i have just wheel_count 4 ?
Posted
Updated 12-Nov-17 3:08am
v2

PHP
static function car_detail(){
    return self::$wheel_count;
    return self::$door_count;
}

The first return statement is the one that exits the function, and returns the value 4. Please go to PHP: PHP Manual - Manual[^] and study the language.
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 12-Nov-17 9:30am    
5ed.
SalahEddine Makkaoui 12-Nov-17 20:34pm    
So if i understand we can return just one value thank you
Richard MacCutchan 13-Nov-17 3:10am    
Basically yes. In your code the second return statement can never be reached.
The second return (return self::$door_count;) is never reached because the first one is the exit point.
 
Share this answer
 
Comments
Richard MacCutchan 13-Nov-17 8:32am    
Exactly what I said yesterday.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900