Assignment in conditional test in PHP

3

I'm studying PHP and I came across a feature that does not exist in Python (I do not know in other languages), which is the assignment in a conditional test:

$file = fopen("arquivo.txt", "w");
while($row = fgets($file)){
    ...
}

Correct me if I am wrong but in a conditional test, it searches to check the result of the condition or the state of the object eg an empty list is false , what we call Truthy and Falsey in Javascript. My doubts are:

  • Does this feature exist only in PHP?
  • How does this work underneath the cloths?
  • asked by anonymous 27.08.2018 / 20:18

    1 answer

    5
      

    Does this feature exist only in PHP?

    No, it exists in almost all languages, and even in Python with some restriction (at least in current version)

      

    How does this work underneath the rags?

    There is nothing much, this is just a syntactic question, it's just the compiler to write so, the execution will be the same as in inline form.

    In Assembly each statement (basic good) goes in a row, high level languages allow to put several of them on the same line, how much this is allowed is the decision of each language. Underneath the cloth even this involves a huge "desabstração", but without wanting to do this in depth we can understand this way (note that while itself is an abstraction):

    inicio:
        $row = fgets($file);
        if (!$row) goto fim;
        ...
        goto inicio;
    fim:
    
        
    27.08.2018 / 20:29