Closed cmette closed 6 months ago
Try this
/* @var Indi $individual */
foreach ($gedcom->getIndi() as $individual) {
/* @var Name $name */
foreach ($individual->getName() as $name) {
echo "id:{$individual->getId()} name:{$name->getName()} surn: {$name->getSurn()}";
// better use
dump("id:{$individual->getId()} name:{$name->getName()} surn: {$name->getSurn()}");
}
}
and fix this in Gedcom\Record\ObjeRef\File\Form;
// add the _ before form like
protected $_form;
// add the _ before titl like
protected $_titl;
// add this line!
protected $_date;
Please send a pull request. Thank you.
8c129a9c07
)[!TIP] I can email you next time I complete a pull request if you set up your email here!
Here are the GitHub Actions logs prior to making any changes:
85517d6
Checking README.md for syntax errors... β README.md has no syntax errors!
1/1 βChecking README.md for syntax errors... β README.md has no syntax errors!
Sandbox passed on the latest main
, so sandbox checks will be enabled for this issue.
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
README.md
β https://github.com/liberu-genealogy/php-gedcom/commit/8b60952e12708d5016e6bd75e6eb5e4c6a3ebefe Edit
Modify README.md with contents:
β’ Replace the existing example code with a corrected version that demonstrates how to properly parse a GEDCOM file and access individual names. The corrected example should avoid using `current()` inappropriately and ensure that it accesses individual names in a manner consistent with the methods provided by the `Indi` and `Name` classes.
β’ Corrected example code: ```php $parser = new \Gedcom\Parser(); $gedcom = $parser->parse('tmp.ged');
foreach ($gedcom->getIndi() as $individual) { $names = $individual->getName(); if (!empty($names)) { $name = reset($names); // Get the first name object from the array echo $individual->getId() . ': ' . $name->getSurn() . ', ' . $name->getGivn() . PHP_EOL; } }
- This modification corrects the syntax errors and logical mistakes in the original example. It uses `reset()` instead of `current()` to get the first element of the names array, which is a safer approach since it resets the array's internal pointer to the first element.
- The corrected example checks if the `$names` array is not empty before attempting to access it, which prevents the "Call to a member function on bool" error.
- The variable `$indi` is removed from the example, as it was incorrectly used and is not defined anywhere in the provided code snippet.
- This modification ensures that the example is executable and provides a clear demonstration of how to access individual names after parsing a GEDCOM file.
<pre>---
+++
@@ -57,7 +57,10 @@
$gedcom = $parser->parse('tmp.ged');
foreach ($gedcom->getIndi() as $individual) {
- echo $individual->getId() . ': ' . current($individual->getName())->getSurn() .
- ', ' . current($indi->$individual())->getGivn();
+ $names = $individual->getName();
+ if (!empty($names)) {
+ $name = reset($names); // Get the first name object from the array
+ echo $individual->getId() . ': ' . $name->getSurn() . ', ' . $name->getGivn() . PHP_EOL;
+ }
}
README.md
β Edit
Check README.md with contents:
Ran GitHub Actions for 8b60952e12708d5016e6bd75e6eb5e4c6a3ebefe:
I have finished reviewing the code for completeness. I did not find errors for sweep/your_example_does_not_work
.
π‘ To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.Something wrong? Let us know.
This is an automated message generated by Sweep AI.
Hello team, your example does not work
this is not a valid php code. Can you give a working example?
These lines are not executable in any PHP version:
In my case the parser seems to work, but I can't access the decoded objects like name etc.
This part
throws an exception
Calling current in foreach should not make sense!
and this part
is not defined, because $indi is not defined and $indi->$individual() makes no sense.
Can you help with a few tips or provide a more detailed example?
Best regards cmette
Checklist
- [X] Modify `README.md` β https://github.com/liberu-genealogy/php-gedcom/commit/8b60952e12708d5016e6bd75e6eb5e4c6a3ebefe [Edit](https://github.com/liberu-genealogy/php-gedcom/edit/sweep/your_example_does_not_work/README.md#L53-L62) - [X] Running GitHub Actions for `README.md` β [Edit](https://github.com/liberu-genealogy/php-gedcom/edit/sweep/your_example_does_not_work/README.md#L53-L62)