小编Viv*_*mbi的帖子

如何调用php中不存在的类方法?

我只想创建像getFieldname()magento 中一样的函数。

例如:

在 Magento 中

getId()ID- 返回字段值

getName()Name- 返回字段值

我怎样才能创建这样的功能?在这种情况下请帮助我..

我想做的就像下面的代码一样,

Class Called{
    $list=array();
    function __construct() {
        
        $this->list["name"]="vivek";
        $this->list["id"]="1";
    }
    function get(){
        echo $this->list[$fieldname];
    }

}

$instance=new Called();

$instance->getId();
$instance->getName();
Run Code Online (Sandbox Code Playgroud)

php oop overriding magento magic-methods

3
推荐指数
1
解决办法
2733
查看次数

可靠地返回结构数组

这是我的合约代码。在这里,我试图存储特定旅行的坐标。同时存储信息合约执行良好。但是当我检索数据时,它应该给出坐标数组。但它抛出一个错误。

原因:'uint256 类型的数据不足'

contract TripHistory {
       struct Trip {
           string lat;
           string lon;
       }
        mapping(string => Trip[]) trips;

        function getTrip(string _trip_id) public view returns (Trip[]) {
            return trips[_trip_id];
        }
        function storeTrip(string _trip_id, string _lat, string _lon) public  {
           trips[_trip_id].push(Trip(_lat, _lon));
        }

}
Run Code Online (Sandbox Code Playgroud)

我在这里缺少什么。有没有其他方法可以实现我在这里尝试的目标?

PS:我是 Solidity 的新手。

ethereum solidity smartcontracts

3
推荐指数
1
解决办法
4579
查看次数