classe properties from an external file

0

Is it possible to do this in some way in php?

Main archive

<?php
    class Class_APP{
        require_once 'propiedades.php';
        public function __construct() {

        }
    }
?>

external file properties.php

<?php
    protected $CONTENTMANAGER;
    protected $MENUMANAGER;
    protected $FORMMANAGER;
    protected $PROCESSMANAGER;
    protected $MODALSMANAGER;
    protected $DBMANAGER;
?>
    
asked by Francisco Núñez 24.10.2017 в 17:35
source

1 answer

0

What you want to do would mark an error but since in php you do not need to define a variable before using it, you could do:

<?php
//propiedades.php
$this->CONTENTMANAGER = null;
$this->MENUMANAGER = null;
$this->FORMMANAGER = null;
$this->PROCESSMANAGER = null;
$this->MODALSMANAGER = null;
$this->DBMANAGER = null;

File of your class:

class Class_APP{



      public function __construct() {
        include ('propiedades.php');
      }
  }

and when doing a var_dump(new Class_APP()); the result would be:

object(Class_APP)#1 (6) {
  ["CONTENTMANAGER"]=>
  NULL
  ["MENUMANAGER"]=>
  NULL
  ["FORMMANAGER"]=>
  NULL
  ["PROCESSMANAGER"]=>
  NULL
  ["MODALSMANAGER"]=>
  NULL
  ["DBMANAGER"]=>
  NULL
}

However, since these properties are dynamically defined, the class does not have the properties and could not inherit them.

    
answered by 25.10.2017 в 01:16