Home > Backend Development > PHP Tutorial > 请教大家一个关于php类的问题

请教大家一个关于php类的问题

WBOY
Release: 2016-06-20 12:43:57
Original
870 people have browsed it

1.php

<?php class test{    public $a = include('./2.php');	  	function testa()	{	   print_r( $this->a);		}}$test = new test;$test->testa();?>
Copy after login


2.php
<?php  return array('status'=>1);?>
Copy after login


通过1.php 输出2.php 里的数组 但是总是报错 请教大家应该怎么写


回复讨论(解决方案)

class test{    public $a;    function test() {      $this->a =  = include('./2.php');    }    function testa()    {       print_r( $this->a);         }}
Copy after login

class test{    public $a;     public function __construct() {      $this->a = include('./2.php');    }     function testa()    {       print_r( $this->a);          }}
Copy after login

放在方法里引入

谢谢大家的热心回答

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template