php / pecl-file_formats-yaml

YAML-1.1 parser and emitter
https://pecl.php.net/package/yaml
MIT License
72 stars 32 forks source link

`yaml_parse_file` does not set `&$ndoc` as expected. #75

Closed tomterl closed 1 year ago

tomterl commented 1 year ago

Description

Given the following yaml file test.yml

---
This is a front-matter
---
doc:
  - prop1: val1
    prop2: val2
...

The following code:

<?php
$nd = 0;
yaml_parse_file("./test.yml", -1, $nd);
echo $nd;

Resulted in this output:

0

But I expected this output instead:

2

The documents are parsed correctly, but without the confirmation of $ndoc > 0, there's no way to tell (could be one document).

yaml_parse behaves as expected:

<?php
$nd = 0;
$yaml = file_get_contents("./test.yml");
yaml_parse($yaml, -1, $nd);
echo $nd;

gives

2

as expected

PHP Version

PHP 8.1.14 / PHP 8.2.1

Operating System

Ubuntu 22.04