findBy function casting issue

For example:

$page->children()->findBy('sku', $sku); // not working

$page->children()->findBy('sku', (string)$sku); // working

Another example:

$page->children()->findBy('sku', 48); // not working

$page->children()->findBy('sku', '48'); // working

By the way, i guess, this issue have other functions that filterBy(), ‘findByUri()’, etc…

I don’t know if this is an issue, the findBy() function expects a string as the second parameter, so this is not surprising.


**
   * Find a single page by a given value
   *
   * @param string $field
   * @param string $value
   * @return Page
   */
  public function findBy($field, $value) {
    foreach($this->data as $page) {
      if($page->$field() == $value) return $page;
    }
    return false;
  }

possible solution like that?

if($page->$field() == (string)$value) return $page;

What is $value?

You can also compare like this

if($page->field()->value() == 'abc') {...;}

Edit: You can always use $field->value() to return a string instead of an object.

Yes, value() method could be use.

Will you PR on GitHub about this issue?