简体   繁体   中英

Passing variable with == in php function

I am working on a project which is previously coded by someone else before years.

I have come to a code where it is written as

$totalTime = $this->getTotalTime($transmissionType == "A", $log);

Here before calling this function I find $transmissionType and its value is M

now the function is defined as

public function getTotalTime($AutGears = false){}

Now $transmissionType = M means manual

Means $AutGears might be the same and $log might not be used.

But I do not get value M in $AutGears. The reason i find is use of == while passing paremeter in

$totalTime = $this->getTotalTime($transmissionType == "A", $log);

I haven't seen use of == like this before, but not sure does it really means anything? Or it is a type error?

If it does not mean anything then I will be removing it and my code will run perfect.

This code is quite old and written in 90s, so I am not sure does this really mean anything.

== returns a boolean value.

$isAutomatic = $transmissionType == "A";  // true or false
$totalTime = $this->getTotalTime($isAutomatic, $log);

Does this way of writing it make more sense…?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM