如何将对象转换为字符串php

时间:2014-06-21 17:35:16

标签: php oop

我正在使用googl-php类创建一个小网址。

我使用过代码:

require_once('Googl.class.php');

$googl = new Googl('xxxxxxx');

$googl->shorten('http://www.example.co.uk/bitsandbobs.php#martello-tower-y-by-billings-jackson-design');

$myText = (string)$googl;
unset($googl);

但这只是返回

  

Googl类的对象无法转换为字符串

2 个答案:

答案 0 :(得分:0)

使用:

$myText = $googl->shorten(
  'http://www.example.co.uk/bitsandbobs.php#martello-tower-y-by-billings-jackson-design'
);

此答案基于您为

提供链接的已发布代码

答案 1 :(得分:0)

可能google类没有魔术方法__toString,你无法做到这一点。

相关问题