0

I´m dealing with Sabre/vobject. To read property values it is necessary to do a casting:

echo (string)$vcard->FN;

I forgot that a few times and observed that for example:

$number = str_replace("\xc2\xa0", "\x20", $card->TEL);
$name = strtoupper($card->FN);

still works.

The PHP manual says:

"...String conversion is automatically done in the scope of an expression where a string is needed. This happens when using the echo or print functions, or when a variable is compared to a string..."

However, I have found no reference to the fact that this also applies to string functions.

5
  • 3
    The first sentence explains that: "String conversion is automatically done in the scope of an expression where a string is needed". In your str_replace(), the third argument needs to be a string or an array. If you pass in something other than an array, it will try and convert it to string. In your echo example, you shouldn't need to convert it to string either, like the second sentence says. Commented Aug 8, 2019 at 11:40
  • Der "echo" line isn´t mine but from sabre/vobject documentation ->Reading property values! Although this is contrary to the PHP manual, it only works in that way (with explicit casting). Commented Aug 8, 2019 at 12:14
  • If you do a var_dump($vcard->FN);, what do you get? What type does the value have? Commented Aug 8, 2019 at 12:17
  • Sorry Magnus, that's not the question Commented Aug 8, 2019 at 19:15
  • I never said that answered the question. It's just basic debugging. If we know what datatype the value has, then we can figure out why you need to cast it when echoing it and not when using str_replace(), since that's not the common behavior. The more info we get, the more likely it is for us to be able to reproduce the issue and answer the actual question. Commented Aug 9, 2019 at 17:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.