当前位置: 首页>>代码示例>>PHP>>正文


PHP MyClass::setProperty方法代码示例

本文整理汇总了PHP中MyClass::setProperty方法的典型用法代码示例。如果您正苦于以下问题:PHP MyClass::setProperty方法的具体用法?PHP MyClass::setProperty怎么用?PHP MyClass::setProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MyClass的用法示例。


在下文中一共展示了MyClass::setProperty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setProperty

<?php

class MyClass
{
    public $prop1 = "I'm a class property!";
    public function setProperty($newval)
    {
        $this->prop1 = $newval;
    }
    public function getProperty()
    {
        return $this->prop1 . "<br />";
    }
}
// Create two objects
$obj = new MyClass();
$obj2 = new MyClass();
// Get the value of $prop1 from both objects
echo $obj->getProperty();
echo $obj2->getProperty();
// Set new values for both objects
$obj->setProperty("I'm a new property value!");
$obj2->setProperty("I belong to the second instance!");
// Output both objects' $prop1 value
echo $obj->getProperty();
echo $obj2->getProperty();
开发者ID:mckennatim,项目名称:php,代码行数:26,代码来源:wayfair.php

示例2: setProperty

-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php 
class MyClass
{
    public $prop1 = "I'm a class property!";
    public function setProperty($newval)
    {
        $this->prop1 = $newval;
    }
    public function getProperty()
    {
        return $this->prop1 . "<br />";
    }
}
$obj = new MyClass();
echo $obj->getProperty();
// Get the property value
$obj->setProperty("I'm a new property value!");
// Set a new one
echo $obj->getProperty();
// Read it out again to show the change
?>
    </body>
</html>
开发者ID:shubhomedia,项目名称:bitm_php,代码行数:30,代码来源:simple_class_file4.php

示例3: setProperty

    public $prop1 = "I'm a class property";
    public function setProperty($newval)
    {
        $this->prop1 = $newval;
    }
    public function getProperty()
    {
        return $this->prop1 . "<br />";
    }
}
$obj = new MyClass();
$obj2 = new MyClass();
echo $obj->getProperty();
echo $obj2->getProperty();
$obj->setProperty("Son! You're close to becoming a developer");
$obj2->setProperty("Son! Welldone!");
echo $obj->getProperty();
echo $obj2->getProperty();
//$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
//echo fread($myfile,filesize("webdictionary.txt"));
//fclose($myfile);
//Using Class Inheritance
class MyOtherClass extends MyClass
{
    public function __construct()
    {
        /*
        Preserving Original Method Functionality While Overwriting Methods
        To add new functionality to an inherited method while keeping the original method intact, use the parent keyword with the scope resolution operator (::):
        */
        parent::__construct();
开发者ID:absmugz,项目名称:zend_certification_practice,代码行数:31,代码来源:index.php


注:本文中的MyClass::setProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。